Advertisement
Korotkodul

CF div2 06.08 D

Aug 6th, 2022 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17.     for (auto x: v) cout<<x<<' ';
  18.     cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22.     for (auto x: v) cout<<x<<' ';
  23.     cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28.     for (auto x: v) cv(x);
  29.     cout<<"\n";
  30. }
  31.  
  32. void cvb(vector <bool> v){
  33.     for (bool x: v) cout<<x<<' ';
  34.     cout<<"\n";
  35. }
  36.  
  37. void cvs(vector <string>  v){
  38.     for (auto a: v){
  39.         cout<<a<<"\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a){
  44.     for (auto p: a){
  45.         cout<<p.first<<' '<<p.second<<"\n";
  46.     }
  47.     cout<<"\n";
  48. }
  49.  
  50.  
  51. bool sh=0;
  52.  
  53. int n, N;
  54.  
  55. // n = 1 - отдельно
  56.  
  57. void slv(){
  58.     int N = pow(2, n);
  59.     vector <int> T(2*N - 1);
  60.     for (int i = N - 1; i < 2*N - 1; ++i){
  61.         T[i] = i - (N - 1);
  62.     }
  63.     int lg = n ;
  64.     int to = pow(2, lg);
  65.     int a=0, b;
  66.     int id = pow(2, lg - 2) + 1;
  67.  
  68.     if (sh){
  69.         cout<<"T\n";
  70.         cv(T);
  71.     }
  72.     while (lg >= 2){
  73.         int Nnow = pow(2, lg - 2);
  74.         id = 2 * Nnow - 1;
  75.         to = pow(2, lg - 1);
  76.         if (sh){
  77.             cout<<"id = "<<id<<"\n";
  78.             cout<<"lg = "<<lg<<"\n";
  79.         }
  80.         for (int i = 0; i < to; ++i){
  81.             a = T[2*id + 1];
  82.             b = T[2*id + 2];
  83.             cout<<"? "<< (a+1)<<' '<<(b+1)<<"\n";
  84.             cout.flush();
  85.             int r;
  86.             cin>>r;
  87.             if (r == 1){
  88.                 T[id] = a;
  89.             }
  90.             else{
  91.                 T[id] = b;
  92.             }
  93.             id++;
  94.         }
  95.         if (sh){
  96.             cout<<"T\n";
  97.             cv(T);
  98.         }
  99.         lg--;
  100.     }
  101.     a = T[1];
  102.     b = T[2];
  103.     cout<<"? "<< (a+1)<<' '<<(b+1)<<"\n";
  104.     cout.flush();
  105.     int r; cin>>r;
  106.     if (r == 1){
  107.         T[0] = a;
  108.     }
  109.     else{
  110.         T[0] = b;
  111.     }
  112.     cout<<"! "<<(T[0] + 1)<<"\n";
  113. }
  114.  
  115. int main()
  116. {
  117.     ios::sync_with_stdio(0);
  118.     cin.tie(0);
  119.     cout.tie(0);
  120.     int t=1;
  121.     if (!sh) cin>>t;
  122.     for (int go = 0; go < t; ++go){
  123.         cin>>n;
  124.         slv();
  125.     }
  126. }
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement