#include <bits/stdc++.h>
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#include "xylophone.h"
typedef long long ll;
using namespace std;
void solve(int N) {
vector<int> a(N + 1), u(2 * N + 1);
int l = 1, r = N + 1;
while (r - l > 1) {
int m = (l + r) / 2;
int get = 0;
if (m < N) get = query(m, N);
if (get != N - 1) r = m;
else l = m;
}
answer(l, 1);
a[l] = 1;
u[1] = 1;
if (l != N) {
a[l + 1] = 1 + query(l, l + 1);
answer(l + 1, a[l + 1]);
u[a[l + 1]] = 1;
}
if (l != 1) {
a[l - 1] = 1 + query(l - 1, l);
answer(l - 1, a[l - 1]);
u[a[l - 1]] = 1;
}
for (int i = l + 2; i <= N; i++) {
int x = query(i - 2, i);
int r = abs(a[i - 1] - a[i - 2]) - x;
if (a[i - 1] < a[i - 2]) {
if (r == 0) {
int y = -1;
for (int j = a[i - 1] + 1; j < a[i - 2]; j++) {
if (!u[j]) {
if (y == -1) y = j;
else {
y = -1;
break;
}
}
}
if (y == -1) y = a[i - 1] + query(i - 1, i);
a[i] = y;
}
else {
if (a[i - 2] <= x + 1 || u[a[i - 2] - x]) a[i] = a[i - 1] + x;
else if (a[i - 1] > N - x || u[a[i - 1] + x]) a[i] = a[i - 2] - x;
else {
int y = query(i - 1, i);
if (y == x) a[i] = a[i - 1] + x;
else a[i] = a[i - 2] - x;
}
}
}
else {
if (r == 0) {
int y = -1;
for (int j = a[i - 2] + 1; j < a[i - 1]; j++) {
if (!u[j]) {
if (y == -1) y = j;
else {
y = -1;
break;
}
}
}
if (y == -1) y = a[i - 1] - query(i - 1, i);
a[i] = y;
}
else {
if (a[i - 1] <= x + 1 || u[a[i - 1] - x]) a[i] = a[i - 2] + x;
else if (a[i - 2] > N - x || u[a[i - 2] + x]) a[i] = a[i - 1] - x;
else {
int y = query(i - 1, i);
if (y == x) a[i] = a[i - 1] - x;
else a[i] = a[i - 2] + x;
}
}
}
answer(i, a[i]);
u[a[i]] = 1;
}
for (int i = l - 2; i >= 1; i--) {
int x = query(i, i + 2);
int r = abs(a[i + 1] - a[i + 2]) - x;
if (a[i + 1] < a[i + 2]) {
if (r == 0) {
int y = -1;
for (int j = a[i + 1] + 1; j < a[i + 2]; j++) {
if (!u[j]) {
if (y == -1) y = j;
else {
y = -1;
break;
}
}
}
if (y == -1) y = a[i + 1] + query(i, i + 1);
a[i] = y;
}
else {
if (a[i + 2] <= x + 1 || u[a[i + 2] - x]) a[i] = a[i + 1] + x;
else if (a[i + 1] > N - x || u[a[i + 1] + x]) a[i] = a[i + 2] - x;
else {
int y = query(i, i + 1);
if (y == x) a[i] = a[i + 1] + x;
else a[i] = a[i + 2] - x;
}
}
}
else {
if (r == 0) {
int y = -1;
for (int j = a[i + 2] + 1; j < a[i + 1]; j++) {
if (!u[j]) {
if (y == -1) y = j;
else {
y = -1;
break;
}
}
}
if (y == -1) y = a[i + 1] - query(i, i + 1);
a[i] = y;
}
else {
if (a[i + 1] <= x + 1 || u[a[i + 1] - x]) a[i] = a[i + 2] + x;
else if (a[i + 2] > N - x || u[a[i + 2] + x]) a[i] = a[i + 1] - x;
else {
int y = query(i, i + 1);
if (y == x) a[i] = a[i + 1] - x;
else a[i] = a[i + 2] + x;
}
}
}
answer(i, a[i]);
u[a[i]] = 1;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
5 ms |
344 KB |
Output is correct |
18 |
Correct |
5 ms |
344 KB |
Output is correct |
19 |
Correct |
7 ms |
344 KB |
Output is correct |
20 |
Correct |
7 ms |
344 KB |
Output is correct |
21 |
Correct |
7 ms |
344 KB |
Output is correct |
22 |
Correct |
6 ms |
344 KB |
Output is correct |
23 |
Correct |
4 ms |
344 KB |
Output is correct |
24 |
Correct |
7 ms |
344 KB |
Output is correct |
25 |
Correct |
7 ms |
344 KB |
Output is correct |
26 |
Correct |
8 ms |
344 KB |
Output is correct |
27 |
Correct |
6 ms |
344 KB |
Output is correct |
28 |
Correct |
8 ms |
344 KB |
Output is correct |
29 |
Correct |
11 ms |
596 KB |
Output is correct |
30 |
Correct |
5 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
5 ms |
344 KB |
Output is correct |
18 |
Correct |
5 ms |
344 KB |
Output is correct |
19 |
Correct |
7 ms |
344 KB |
Output is correct |
20 |
Correct |
7 ms |
344 KB |
Output is correct |
21 |
Correct |
7 ms |
344 KB |
Output is correct |
22 |
Correct |
6 ms |
344 KB |
Output is correct |
23 |
Correct |
4 ms |
344 KB |
Output is correct |
24 |
Correct |
7 ms |
344 KB |
Output is correct |
25 |
Correct |
7 ms |
344 KB |
Output is correct |
26 |
Correct |
8 ms |
344 KB |
Output is correct |
27 |
Correct |
6 ms |
344 KB |
Output is correct |
28 |
Correct |
8 ms |
344 KB |
Output is correct |
29 |
Correct |
11 ms |
596 KB |
Output is correct |
30 |
Correct |
5 ms |
344 KB |
Output is correct |
31 |
Correct |
16 ms |
344 KB |
Output is correct |
32 |
Correct |
24 ms |
344 KB |
Output is correct |
33 |
Correct |
38 ms |
344 KB |
Output is correct |
34 |
Correct |
37 ms |
344 KB |
Output is correct |
35 |
Correct |
40 ms |
344 KB |
Output is correct |
36 |
Correct |
24 ms |
344 KB |
Output is correct |
37 |
Incorrect |
67 ms |
344 KB |
Wrong Answer [2] |
38 |
Halted |
0 ms |
0 KB |
- |