fork(1) download
  1. #include <bits/stdc++.h>
  2. #define pi 3.14159265359
  3. using namespace std;
  4.  
  5. int main() {
  6. int N;
  7. cin >> N;
  8. int a =(N+1)/2;
  9. if(N == 1) {cout << "A 1\n"; return 0;}
  10. cout << "Q 1 " << a << "\n";
  11. cout.flush();
  12. vector<int> S(N+42,0);
  13. set<int> s;
  14. for(int i =0; i < a; i++) {
  15. int x;
  16. cin >> x;
  17. S[0] +=x;
  18. s.insert(x);}
  19. if(N == 2) {cout << "A " << *s.begin() << " " << 3-*s.begin() << "\n"; return 0;}
  20. vector<int> ans(N);
  21. for(int i =0; i < a-1; i++) {
  22. cout << "Q " << i+2 << " " << i+1+a << "\n";
  23. cout.flush();
  24. set<int> s2;
  25. for(int j =0; j < a; j++) {
  26. int x;
  27. cin >> x;
  28. S[i+1] +=x;
  29. s2.insert(x);
  30. if(s.find(x) == s.end()) ans[i+a] =x;}
  31. for(auto it =s.begin(); it != s.end(); it++) if(s2.find(*it) == s2.end())
  32. ans[i] =*it;
  33. s =s2;}
  34. for(int i =0; i < N-a; i++) if(ans[i+a-1] == 0) {
  35. for(int j =0; j < a; j++) S[i] -=ans[i+j];
  36. ans[i+a-1] =S[i];}
  37. if(ans[N-1] == 0) {
  38. long long x =N*(N+1)/2;
  39. for(int i =0; i < N-1; i++) x -=ans[i];
  40. ans[N-1] =x;}
  41. cout << "A ";
  42. for(int i =0; i < N; i++) cout << ans[i] << ((i == N-1)?"\n":" ");
  43. return 0;}
Success #stdin #stdout 0s 3436KB
stdin
7
7 6 5 4
6 5 4 3
5 4 3 2
4 3 2 1
stdout
Q 1 4
Q 2 5
Q 3 6
Q 4 7
A 7 6 5 4 3 2 1