Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- #define all(x) x.begin(), x.end()
- #define rall(x) x.rbegin(), x.rend()
- //#define endl '\n'
- #define boostIO() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
- vector<int> inv(vector<int> A) {
- vector<int> B(A.size());
- for (int i = 1; i <= A.size(); ++i) {
- B[A[i - 1] - 1] = i;
- }
- return B;
- }
- vector<int> fuck(vector<int> A, vector<int> B) {
- vector<int> C(A.size());
- for (int i = 0; i < A.size(); ++i) {
- C[i] = B[A[i] - 1];
- }
- return C;
- }
- signed main() {
- int q;
- cin >> q;
- while (q--) {
- int n;
- cin >> n;
- cout << "? ";
- vector<int> v(n);
- for (int i = 0; i < n; ++i) {
- v[i] = 1 + (i + 1) % n;
- cout << v[i] << " ";
- }
- cout << endl;
- vector<int> ans(n), res(n), in(n);
- for (auto& x : in) cin >> x;
- for (int k = 0; k <= 1; ++k) {
- for (int i = 0; i < n; ++i) {
- res[i] = in[(2 * n - 2 - k - i) % n];
- }
- if (fuck(fuck(res, v), inv(res)) == in) ans = inv(res);
- }
- cout << "! ";
- for (auto x : ans) cout << x << " ";
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement