Advertisement
Korotkodul

CF div2 06.08 D 1

Aug 6th, 2022 (edited)
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.45 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.     //cout<<"n N = "<<n<<' '<<N<<"\n";
  68.     if (sh){
  69.         cout<<"T\n";
  70.         cv(T);
  71.         //cout.flush();
  72.     }
  73.     while (lg >= 2){
  74.         int Nnow = pow(2, lg - 2);
  75.         id = 2 * Nnow - 1;
  76.         to = pow(2, lg - 2);
  77.         if (sh){
  78.             cout<<"id = "<<id<<"\n";
  79.             cout<<"lg = "<<lg<<"\n";
  80.             //cout.flush();
  81.         }
  82.         for (int i = 0; i < to; i++){
  83.             a = T[2*id + 1];
  84.             b = T[2*(id+1) + 1];
  85.             cout<<"? "<< (a+1)<<' '<<(b+1)<<"\n";
  86.             cout.flush();
  87.             int r;
  88.             cin>>r;
  89.             if (r == 1){
  90.                 if (sh){
  91.                     cout<<"A\n";
  92.                 }
  93.                 T[id] = a;
  94.                 T[id + 1] = T[2*(id+1) + 2];
  95.             }
  96.             else if (r == 2) {
  97.                 if (sh){
  98.                     cout<<"B\n";
  99.                 }
  100.                 T[id + 1] = b;
  101.                 T[id] = T[2*id + 2];
  102.             }
  103.             else{//худший случай
  104.                 cout<<"? "<< (a+1)<<' '<<(T[2*(id+1) + 2]+1)<<"\n";
  105.                 cout.flush();
  106.                 cin>>r;
  107.                 if (r == 1){
  108.                     if (sh){
  109.                         cout<<"C\n";
  110.                     }
  111.                     T[id] = a;
  112.                     T[id + 1] = b;
  113.                 }
  114.                 else{//r == 2
  115.                      if (sh){
  116.                         cout<<"D\n";
  117.                     }
  118.                     T[id + 1] = T[2*(id+1) + 2];
  119.                     T[id] = T[2*id + 2];
  120.                 }
  121.             }
  122.             id+=2;
  123.             if (sh){
  124.                 cout<<"i to = "<<i<<' '<<to<<"\n";
  125.             }
  126.         }
  127.         if (sh){
  128.             cout<<"T\n";
  129.             //cout.flush();
  130.             cv(T);
  131.             //cout.flush();
  132.         }
  133.         lg--;
  134.     }
  135.     a = T[1];
  136.     b = T[2];
  137.     cout<<"? "<< (a+1)<<' '<<(b+1)<<"\n";
  138.     cout.flush();
  139.     int r; cin>>r;
  140.     if (r == 1){
  141.         T[0] = a;
  142.     }
  143.     else{
  144.         T[0] = b;
  145.     }
  146.     cout<<"! "<<(T[0] + 1)<<"\n";
  147. }
  148.  
  149. int main()
  150. {
  151.     /*ios::sync_with_stdio(0);
  152.     cin.tie(0);
  153.     cout.tie(0);*/
  154.     int t=1;
  155.     if (!sh) cin>>t;
  156.     for (int go = 0; go < t; ++go){
  157.         cin>>n;
  158.         slv();
  159.     }
  160. }
  161. /*
  162. 1
  163. 3
  164. ? 1 3
  165. 0
  166. ? 1 4
  167. 1
  168. ? 5 7
  169. 0
  170. ? 5 8
  171. 2
  172.  
  173.  
  174. ? 1 0
  175. */
  176.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement