-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC.cpp
More file actions
61 lines (59 loc) · 1.15 KB
/
Copy pathC.cpp
File metadata and controls
61 lines (59 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <bits/stdc++.h>
using namespace std;
#define cerr cerr << "DEBUG "
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tc;
cin >> tc;
while (tc--) {
int n;
cin >> n;
set<int> tmp;
for (int i = 0; i < n; ++i) {
tmp.insert(i);
}
cout << "? " << 1 << endl;
int xx;
cin >> xx;
vector<bool> mark(n);
vector<int> f(n, -1);
while ((int) tmp.size() > 1) {
int i = *tmp.begin();
cout << "? " << i + 1 << endl;
int last;
cin >> last;
if (last == 0) {
exit(0);
}
--last;
while ((int) tmp.size() > 1) {
cout << "? " << i + 1 << endl;
int x;
cin >> x;
if (x == 0) {
exit(0);
}
--x;
//cerr << mark[last] << ' ' << mark[x] << ' ' << last << ' ' << x << '\n';
f[last] = x;
tmp.erase(last);
mark[last] = true;
if (last == x) {
break;
}
if (mark[x]) {
break;
}
last = x;
}
}
long long sum = accumulate(f.begin(), f.end(), 0ll) + 1;
f[*tmp.begin()] = 1ll * n * (n - 1) / 2 - sum;
cout << "! ";
for (auto &i : f) {
cout << i + 1 << ' ';
}
cout << endl;
}
}