Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- int main()
- {
- _test
- {
- auto ask = [](int x)
- {
- cout<<"? "<<x<<endl;
- int tmp;
- cin>>tmp;
- return tmp;
- };
- int n, k;
- cin>>n>>k;
- int XOR = 0;
- int i;
- for(i=1; i+k-1<=n; i+=k)
- XOR ^= ask(i);
- if(i > n)
- {
- cout<<"! "<<XOR<<endl;
- continue;
- }
- int x = ask(n-k+1 - (n%k)/2);
- int y = ask(n-k+1);
- XOR ^= (x^y);
- cout<<"! "<<XOR<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement