Advertisement
Georgiy031

Untitled

Nov 22nd, 2020
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. typedef long long ll;
  5. typedef unsigned long long ull;
  6. #define all(x) x.begin(), x.end()
  7. #define rall(x) x.rbegin(), x.rend()
  8. //#define endl '\n'
  9. #define boostIO() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  10. ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
  11.  
  12. vector<int> inv(vector<int> A) {
  13.     vector<int> B(A.size());
  14.     for (int i = 1; i <= A.size(); ++i) {
  15.         B[A[i - 1] - 1] = i;
  16.     }
  17.     return B;
  18. }
  19.  
  20. vector<int> fuck(vector<int> A, vector<int> B) {
  21.     vector<int> C(A.size());
  22.     for (int i = 0; i < A.size(); ++i) {
  23.         C[i] = B[A[i] - 1];
  24.     }
  25.     return C;
  26. }
  27.  
  28. signed main() {
  29.     int q;
  30.     cin >> q;
  31.     while (q--) {
  32.         int n;
  33.         cin >> n;
  34.         cout << "? ";
  35.         vector<int> v(n);
  36.         for (int i = 0; i < n; ++i) {
  37.             v[i] = 1 + (i + 1) % n;
  38.             cout << v[i] << " ";
  39.         }
  40.         cout << endl;
  41.         vector<int> ans(n), res(n), in(n);
  42.         for (auto& x : in) cin >> x;
  43.  
  44.         for (int k = 0; k <= 1; ++k) {
  45.             for (int i = 0; i < n; ++i) {
  46.                 res[i] = in[(2 * n - 2 - k - i) % n];
  47.             }
  48.             if (fuck(fuck(res, v), inv(res)) == in) ans = inv(res);
  49.         }
  50.  
  51.         cout << "! ";
  52.         for (auto x : ans) cout << x << " ";
  53.         cout << endl;
  54.     }
  55.  
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement