#include <bits/stdc++.h>
using namespace std;
#include "xylophone.h"
//#include "grader.cpp"
void solve(int n) {
vector<int> a(n + 1), d(n + 1);
for (int i = 1; i < n; ++i) {
d[i] = query(i, i + 1);
}
int min = 1, hi = n;
while (min + 1 < hi) {
int mid = (min + hi) / 2;
if ((mid + 1 < n ? query(mid, n) : d[mid]) == n - 1) min = mid;
else hi = mid;
}
a[min] = 1;
int last = min, sum = 0;
bool increasing = true;
map<int, bool> used;
used[1] = true;
for (int i = min - 1; i > 0; --i) {
int add = d[i];
if (increasing && (used[a[i + 1] + add] || a[i + 1] + add > n)) {
increasing = false, sum = 0, last = i + 1;
} else if (!increasing && (used[a[i + 1] - add] || a[i + 1] - add <= 0)) {
increasing = true, sum = 0, last = i + 1;
} else {
int diff = (i + 1 < last ? query(i, last) : d[i]);
if (sum + add != diff) {
last = i + 1, sum = 0;
increasing ^= true;
}
}
a[i] = a[i + 1] + (increasing ? add : -add);
used[a[i]] = true;
sum += add;
}
last = min, sum = 0;
increasing = true;
for (int i = min + 1; i <= n; ++i) {
int add = d[i - 1];
if (increasing && (used[a[i - 1] + add] || a[i - 1] + add > n)) {
increasing = false, sum = 0, last = i - 1;
} else if (!increasing && (used[a[i - 1] - add] || a[i - 1] - add <= 0)) {
increasing = true, sum = 0, last = i - 1;
} else {
int diff = (last + 1 < i ? query(last, i) : d[last]);
if (sum + add != diff) {
last = i - 1, sum = 0;
increasing ^= true;
}
}
a[i] = a[i - 1] + (increasing ? add : -add);
used[a[i]] = true;
sum += add;
}
for (int i = 1; i <= n; ++i) {
answer(i, a[i]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
440 KB |
Output is correct |
5 |
Correct |
1 ms |
436 KB |
Output is correct |
6 |
Correct |
1 ms |
436 KB |
Output is correct |
7 |
Correct |
1 ms |
436 KB |
Output is correct |
8 |
Correct |
1 ms |
440 KB |
Output is correct |
9 |
Correct |
1 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
436 KB |
Output is correct |
11 |
Correct |
1 ms |
432 KB |
Output is correct |
12 |
Correct |
1 ms |
436 KB |
Output is correct |
13 |
Correct |
1 ms |
436 KB |
Output is correct |
14 |
Correct |
1 ms |
436 KB |
Output is correct |
15 |
Correct |
1 ms |
436 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 |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
440 KB |
Output is correct |
5 |
Correct |
1 ms |
436 KB |
Output is correct |
6 |
Correct |
1 ms |
436 KB |
Output is correct |
7 |
Correct |
1 ms |
436 KB |
Output is correct |
8 |
Correct |
1 ms |
440 KB |
Output is correct |
9 |
Correct |
1 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
436 KB |
Output is correct |
11 |
Correct |
1 ms |
432 KB |
Output is correct |
12 |
Correct |
1 ms |
436 KB |
Output is correct |
13 |
Correct |
1 ms |
436 KB |
Output is correct |
14 |
Correct |
1 ms |
436 KB |
Output is correct |
15 |
Correct |
1 ms |
436 KB |
Output is correct |
16 |
Correct |
2 ms |
688 KB |
Output is correct |
17 |
Correct |
3 ms |
440 KB |
Output is correct |
18 |
Correct |
5 ms |
956 KB |
Output is correct |
19 |
Correct |
6 ms |
696 KB |
Output is correct |
20 |
Correct |
6 ms |
448 KB |
Output is correct |
21 |
Correct |
6 ms |
700 KB |
Output is correct |
22 |
Correct |
8 ms |
700 KB |
Output is correct |
23 |
Correct |
8 ms |
696 KB |
Output is correct |
24 |
Correct |
4 ms |
440 KB |
Output is correct |
25 |
Correct |
5 ms |
440 KB |
Output is correct |
26 |
Correct |
8 ms |
440 KB |
Output is correct |
27 |
Correct |
5 ms |
440 KB |
Output is correct |
28 |
Correct |
8 ms |
1220 KB |
Output is correct |
29 |
Correct |
7 ms |
444 KB |
Output is correct |
30 |
Correct |
6 ms |
700 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 |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
440 KB |
Output is correct |
5 |
Correct |
1 ms |
436 KB |
Output is correct |
6 |
Correct |
1 ms |
436 KB |
Output is correct |
7 |
Correct |
1 ms |
436 KB |
Output is correct |
8 |
Correct |
1 ms |
440 KB |
Output is correct |
9 |
Correct |
1 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
436 KB |
Output is correct |
11 |
Correct |
1 ms |
432 KB |
Output is correct |
12 |
Correct |
1 ms |
436 KB |
Output is correct |
13 |
Correct |
1 ms |
436 KB |
Output is correct |
14 |
Correct |
1 ms |
436 KB |
Output is correct |
15 |
Correct |
1 ms |
436 KB |
Output is correct |
16 |
Correct |
2 ms |
688 KB |
Output is correct |
17 |
Correct |
3 ms |
440 KB |
Output is correct |
18 |
Correct |
5 ms |
956 KB |
Output is correct |
19 |
Correct |
6 ms |
696 KB |
Output is correct |
20 |
Correct |
6 ms |
448 KB |
Output is correct |
21 |
Correct |
6 ms |
700 KB |
Output is correct |
22 |
Correct |
8 ms |
700 KB |
Output is correct |
23 |
Correct |
8 ms |
696 KB |
Output is correct |
24 |
Correct |
4 ms |
440 KB |
Output is correct |
25 |
Correct |
5 ms |
440 KB |
Output is correct |
26 |
Correct |
8 ms |
440 KB |
Output is correct |
27 |
Correct |
5 ms |
440 KB |
Output is correct |
28 |
Correct |
8 ms |
1220 KB |
Output is correct |
29 |
Correct |
7 ms |
444 KB |
Output is correct |
30 |
Correct |
6 ms |
700 KB |
Output is correct |
31 |
Correct |
15 ms |
952 KB |
Output is correct |
32 |
Correct |
22 ms |
624 KB |
Output is correct |
33 |
Correct |
35 ms |
724 KB |
Output is correct |
34 |
Correct |
44 ms |
1232 KB |
Output is correct |
35 |
Correct |
35 ms |
976 KB |
Output is correct |
36 |
Incorrect |
46 ms |
976 KB |
Wrong Answer [2] |
37 |
Halted |
0 ms |
0 KB |
- |