Advertisement
Ankit_132

E2

Sep 11th, 2023
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  7.  
  8. int main()
  9. {
  10.     _test
  11.     {
  12.         auto ask = [](int x)
  13.         {
  14.             cout<<"? "<<x<<endl;
  15.             int tmp;
  16.             cin>>tmp;
  17.             return tmp;
  18.         };
  19.  
  20.         int n, k;
  21.         cin>>n>>k;
  22.  
  23.         int XOR = 0;
  24.  
  25.         int i;
  26.         for(i=1; i+k-1<=n; i+=k)
  27.             XOR ^= ask(i);
  28.  
  29.         if(i > n)
  30.         {
  31.             cout<<"! "<<XOR<<endl;
  32.             continue;
  33.         }
  34.  
  35.         int x = ask(n-k+1 - (n%k)/2);
  36.         int y = ask(n-k+1);
  37.         XOR ^= (x^y);
  38.  
  39.         cout<<"! "<<XOR<<endl;
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement