-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2032D.cpp
More file actions
58 lines (49 loc) · 1.32 KB
/
2032D.cpp
File metadata and controls
58 lines (49 loc) · 1.32 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
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
int query(int i, int j) {
// Replace this logic with the actual logic of your query function.
return (i + j) % 3; // This is just a placeholder; modify as needed.
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int flag = 0;
vector<int> s;
vector<int> ans(n + 1, 0);
for (int i = 2; i <= n; ++i) {
if (!flag) {
int x = query(i, 1);
if (x == -1) {
return 0;
}
s.push_back(i);
if (x == 0) {
flag = 1;
ans[i] = 1;
}
} else {
while (!s.empty()) {
int x = s[0];
s.erase(s.begin());
int y = query(i, x);
if (y == 0) {
ans[i] = x;
s.push_back(i);
break;
}
}
}
}
printf("! ");
for (int i = 1; i <= n; ++i) {
printf("%d ", ans[i]);
}
printf("\n");
}
return 0;
}