fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int ask(int l,int r){
  5. cout << "AK " << l << " " << r << "\n" << flush;
  6. string s;
  7. if(!(cin >> s)) exit(0);
  8. return s == "O";
  9. }
  10.  
  11. int main(){
  12. ios::sync_with_stdio(false);
  13. cin.tie(nullptr);
  14. int T;
  15. if(!(cin >> T)) return 0;
  16. while(T--){
  17. int N;
  18. if(!(cin >> N)) return 0;
  19. int lo=1, hi=N;
  20. while(lo<hi){
  21. int mid=(lo+hi)/2;
  22. if(ask(1,mid)) hi=mid;
  23. else lo=mid+1;
  24. }
  25. int a=lo;
  26. lo=1; hi=N;
  27. while(lo<hi){
  28. int mid=(lo+hi+1)/2;
  29. if(ask(1,mid)) lo=mid;
  30. else hi=mid-1;
  31. }
  32. int last = lo;
  33. int b = last + 1;
  34. cout << "! " << a << " " << b << "\n" << flush;
  35. }
  36. return 0;
  37. }
Success #stdin #stdout 0.01s 5292KB
stdin
1
10

X

O

X

X

O

X
stdout
AK 1 5
AK 1 8
AK 1 7
AK 1 6
AK 1 3
AK 1 4
! 8 4