#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
void solve(int n) {
int lo = 1, hi = n;
vector <int> a(n + 1, 0), vis(n + 1, 0);
while (lo < hi) {
int mid = (lo + hi + 1) / 2, val = query(mid, n);
if (val == n - 1)
lo = mid;
else
hi = mid - 1;
}
a[lo] = 1;
vis[1] = 1;
if (lo > 1) {
int val = query(lo - 1, lo);
a[lo - 1] = val + 1;
vis[val + 1] = 1;
for (int i = lo - 2; i > 0; i --) {
val = query(i, i + 1);
vector <int> g;
if (a[i + 1] - val > 0 && !vis[a[i + 1] - val])
g.push_back(a[i + 1] - val);
if (a[i + 1] + val <= n && !vis[a[i + 1] + val])
g.push_back(a[i + 1] + val);
if (g.size() == 1) {
a[i] = g[0];
vis[a[i]] = 1;
}
else {
int val_ = max({g[0], a[i + 1], a[i + 2]}) - min({g[0], a[i + 1], a[i + 2]});
if (val_ == query(i, i + 2)) {
a[i] = g[0];
vis[a[i]] = 1;
}
else {
a[i] = g[1];
vis[a[i]] = 1;
}
}
}
}
int val = query(lo, lo + 1);
a[lo + 1] = val + 1;
vis[val + 1] = 1;
for (int i = lo + 2; i <= n; i ++) {
val = query(i - 1, i);
vector <int> g;
if (a[i - 1] - val > 0 && !vis[a[i - 1] - val])
g.push_back(a[i - 1] - val);
if (a[i - 1] + val <= n && !vis[a[i - 1] + val])
g.push_back(a[i - 1] + val);
if (g.size() == 1) {
a[i] = g[0];
vis[a[i]] = 1;
}
else {
int val_ = max({g[0], a[i - 1], a[i - 2]}) - min({g[0], a[i - 1], a[i - 2]});
if (val_ == query(i - 2, i)) {
a[i] = g[0];
vis[a[i]] = 1;
}
else {
a[i] = g[1];
vis[a[i]] = 1;
}
}
}
for (int i = 1; i <= n; i ++)
answer(i, a[i]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
252 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
252 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
6 ms |
208 KB |
Output is correct |
18 |
Correct |
7 ms |
208 KB |
Output is correct |
19 |
Correct |
10 ms |
288 KB |
Output is correct |
20 |
Correct |
11 ms |
292 KB |
Output is correct |
21 |
Correct |
11 ms |
288 KB |
Output is correct |
22 |
Correct |
8 ms |
208 KB |
Output is correct |
23 |
Correct |
4 ms |
304 KB |
Output is correct |
24 |
Correct |
9 ms |
208 KB |
Output is correct |
25 |
Correct |
8 ms |
308 KB |
Output is correct |
26 |
Correct |
12 ms |
208 KB |
Output is correct |
27 |
Correct |
9 ms |
208 KB |
Output is correct |
28 |
Correct |
6 ms |
312 KB |
Output is correct |
29 |
Correct |
5 ms |
308 KB |
Output is correct |
30 |
Correct |
12 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
252 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
6 ms |
208 KB |
Output is correct |
18 |
Correct |
7 ms |
208 KB |
Output is correct |
19 |
Correct |
10 ms |
288 KB |
Output is correct |
20 |
Correct |
11 ms |
292 KB |
Output is correct |
21 |
Correct |
11 ms |
288 KB |
Output is correct |
22 |
Correct |
8 ms |
208 KB |
Output is correct |
23 |
Correct |
4 ms |
304 KB |
Output is correct |
24 |
Correct |
9 ms |
208 KB |
Output is correct |
25 |
Correct |
8 ms |
308 KB |
Output is correct |
26 |
Correct |
12 ms |
208 KB |
Output is correct |
27 |
Correct |
9 ms |
208 KB |
Output is correct |
28 |
Correct |
6 ms |
312 KB |
Output is correct |
29 |
Correct |
5 ms |
308 KB |
Output is correct |
30 |
Correct |
12 ms |
208 KB |
Output is correct |
31 |
Correct |
28 ms |
208 KB |
Output is correct |
32 |
Correct |
35 ms |
304 KB |
Output is correct |
33 |
Correct |
37 ms |
316 KB |
Output is correct |
34 |
Correct |
58 ms |
336 KB |
Output is correct |
35 |
Correct |
58 ms |
336 KB |
Output is correct |
36 |
Correct |
19 ms |
328 KB |
Output is correct |
37 |
Correct |
36 ms |
320 KB |
Output is correct |
38 |
Correct |
41 ms |
336 KB |
Output is correct |
39 |
Correct |
63 ms |
336 KB |
Output is correct |
40 |
Correct |
58 ms |
336 KB |
Output is correct |
41 |
Correct |
28 ms |
336 KB |
Output is correct |
42 |
Correct |
34 ms |
336 KB |
Output is correct |
43 |
Correct |
46 ms |
316 KB |
Output is correct |
44 |
Correct |
47 ms |
336 KB |
Output is correct |
45 |
Correct |
42 ms |
336 KB |
Output is correct |
46 |
Correct |
51 ms |
384 KB |
Output is correct |
47 |
Correct |
55 ms |
336 KB |
Output is correct |
48 |
Correct |
66 ms |
336 KB |
Output is correct |
49 |
Correct |
42 ms |
336 KB |
Output is correct |
50 |
Correct |
52 ms |
336 KB |
Output is correct |
51 |
Correct |
36 ms |
380 KB |
Output is correct |
52 |
Correct |
32 ms |
316 KB |
Output is correct |
53 |
Correct |
57 ms |
316 KB |
Output is correct |
54 |
Correct |
54 ms |
336 KB |
Output is correct |
55 |
Correct |
50 ms |
336 KB |
Output is correct |
56 |
Correct |
54 ms |
316 KB |
Output is correct |
57 |
Correct |
40 ms |
316 KB |
Output is correct |
58 |
Correct |
41 ms |
444 KB |
Output is correct |
59 |
Correct |
47 ms |
340 KB |
Output is correct |
60 |
Correct |
40 ms |
316 KB |
Output is correct |