Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define db long double
  4. #define x first
  5. #define y second
  6. #define mp make_pair
  7. #define pb push_back
  8. #define all(a) a.begin(), a.end()
  9.  
  10. using namespace std;
  11.  
  12. int n;
  13.  
  14. char ask(int a, int b) {
  15.     cout << "? " << a << ' ' << b << endl;
  16.     char c;
  17.     cin >> c;
  18.     return c;
  19. }
  20.  
  21. int main(){
  22.  
  23.     cin >> n;
  24.  
  25.     vector<int> t;
  26.     char c = ask(1, 2);
  27.     t.pb(1);
  28.     t.pb(2);
  29.     int last = 3;
  30.     int uk = 0;
  31.  
  32.     while (last <= n) {
  33.         int new_node = last++;
  34.         if (uk == 0) {
  35.             auto new_c = ask(t.back(), new_node);
  36.             if (new_c == c) {
  37.                 t.pb(new_node);
  38.                 continue;
  39.             } else {
  40.                 uk = (int)t.size() - 1;
  41.                 t.pb(new_node);
  42.                 continue;
  43.             }
  44.         }
  45.  
  46.  
  47.         auto new_c = ask(t[uk], new_node);
  48.  
  49.         if (new_c == c) {
  50.             int uk2;
  51.             auto sec_c = ask(t.back(), new_node);
  52.             vector<int> d;
  53.             for (int i = 0; i < uk; ++i) d.pb(t[i]);
  54.             d.pb(new_node);
  55.             if (sec_c == c) {
  56.                 uk2 = d.size();
  57.             } else {
  58.                 uk2 = (int)d.size() - 1;
  59.             }
  60.             for (int i = (int)t.size() - 1; i >= uk; --i) d.pb(t[i]);
  61.             uk = uk2;
  62.             t = d;
  63.         } else {
  64.             auto sec_c = ask(t[uk - 1], t.back());
  65.  
  66.             vector<int> d;
  67.             for (int i = 0; i < uk; ++i) d.pb(t[i]);
  68.             for (int i = (int)t.size() - 1; i >= uk; --i) d.pb(t[i]);
  69.             d.pb(new_node);
  70.  
  71.             if (sec_c == c) {
  72.                 uk = uk;
  73.             } else {
  74.                 uk = uk - 1;
  75.             }
  76.             t = d;
  77.         }
  78.     }
  79.  
  80.     cout << "! ";
  81.     for (int x : t) cout << x << ' ';
  82.     cout << endl;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement