// In the name of the God
#include "xylophone.h"
#include <bits/stdc++.h>
#define ll long long
// #define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;
const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 1e4+5;
int a[maxn];
bool mark[maxn];
void solve(int n) {
// if (n == 2) {
// answer(1, 1), answer(2, 2); return;
// }
int l = 1, r = n+1;
while (r-l > 1) {
int mid = (r+l)/2;
if (query(1, mid) == n-1) r = mid;
else l = mid;
}
a[++l] = n, mark[n] = 1;
if (l < n) {
int x = query(l, l+1);
a[l+1] = n-x, mark[n-x] = 1;
for (int i = l+2; i <= n; i++) {
int p = query(i-1, i);
if (mark[a[i-1]+p]) {
a[i] = a[i-1]-p, mark[a[i-1]-p] = 1;
}
else if (mark[a[i-1]-p]) {
a[i] = a[i-1]+p, mark[a[i-1]+p] = 1;
}
else if (a[i-2] > a[i-1]) {
int r = query(i-2, i);
if (r == a[i-2]-(a[i-1]-p)) {
a[i] = a[i-1]-p, mark[a[i-1]-p] = 1;
}
else {
a[i] = a[i-1]+p, mark[a[i-1]+p] = 1;
}
}
else {
int r = query(i-2, i);
if (r == (a[i-1]+p)-a[i-2]) {
a[i] = a[i-1]+p, mark[a[i-1]+p] = 1;
}
else {
a[i] = a[i-1]-p, mark[a[i-1]-p] = 1;
}
}
}
}
int x = query(l-1, l);
a[l-1] = n-x, mark[n-x] = 1;
for (int i = l-2; i >= 1; i--) {
int p = query(i, i+1);
if (mark[a[i+1]+p]) {
a[i] = a[i+1]-p, mark[a[i+1]-p] = 1;
}
else if (mark[a[i+1]-p]) {
a[i] = a[i+1]+p, mark[a[i+1]+p] = 1;
}
else if (a[i+2] > a[i+1]) {
int r = query(i, i+2);
if (r == a[i+2]-(a[i+1]-p)) {
a[i] = a[i+1]-p, mark[a[i+1]-p] = 1;
}
else {
a[i] = a[i+1]+p, mark[a[i+1]+p] = 1;
}
}
else {
int r = query(i, i+2);
if (r == (a[i+1]+p)-a[i+2]) {
a[i] = a[i+1]+p, mark[a[i+1]+p] = 1;
}
else {
a[i] = a[i+1]-p, mark[a[i+1]-p] = 1;
}
}
}
for (int i = 1; i <= n; i++) answer(i, a[i]);
}
// int32_t main() {
// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// return 0;
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
440 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Correct |
0 ms |
440 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 |
440 KB |
Output is correct |
8 |
Correct |
1 ms |
436 KB |
Output is correct |
9 |
Correct |
1 ms |
440 KB |
Output is correct |
10 |
Correct |
1 ms |
436 KB |
Output is correct |
11 |
Correct |
1 ms |
436 KB |
Output is correct |
12 |
Correct |
1 ms |
440 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
440 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Correct |
0 ms |
440 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 |
440 KB |
Output is correct |
8 |
Correct |
1 ms |
436 KB |
Output is correct |
9 |
Correct |
1 ms |
440 KB |
Output is correct |
10 |
Correct |
1 ms |
436 KB |
Output is correct |
11 |
Correct |
1 ms |
436 KB |
Output is correct |
12 |
Correct |
1 ms |
440 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 |
440 KB |
Output is correct |
17 |
Correct |
3 ms |
692 KB |
Output is correct |
18 |
Correct |
7 ms |
692 KB |
Output is correct |
19 |
Correct |
8 ms |
700 KB |
Output is correct |
20 |
Correct |
5 ms |
444 KB |
Output is correct |
21 |
Correct |
6 ms |
444 KB |
Output is correct |
22 |
Correct |
6 ms |
700 KB |
Output is correct |
23 |
Correct |
4 ms |
952 KB |
Output is correct |
24 |
Correct |
7 ms |
444 KB |
Output is correct |
25 |
Correct |
7 ms |
444 KB |
Output is correct |
26 |
Correct |
6 ms |
696 KB |
Output is correct |
27 |
Correct |
7 ms |
696 KB |
Output is correct |
28 |
Correct |
7 ms |
696 KB |
Output is correct |
29 |
Correct |
6 ms |
952 KB |
Output is correct |
30 |
Correct |
6 ms |
696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
440 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Correct |
0 ms |
440 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 |
440 KB |
Output is correct |
8 |
Correct |
1 ms |
436 KB |
Output is correct |
9 |
Correct |
1 ms |
440 KB |
Output is correct |
10 |
Correct |
1 ms |
436 KB |
Output is correct |
11 |
Correct |
1 ms |
436 KB |
Output is correct |
12 |
Correct |
1 ms |
440 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 |
440 KB |
Output is correct |
17 |
Correct |
3 ms |
692 KB |
Output is correct |
18 |
Correct |
7 ms |
692 KB |
Output is correct |
19 |
Correct |
8 ms |
700 KB |
Output is correct |
20 |
Correct |
5 ms |
444 KB |
Output is correct |
21 |
Correct |
6 ms |
444 KB |
Output is correct |
22 |
Correct |
6 ms |
700 KB |
Output is correct |
23 |
Correct |
4 ms |
952 KB |
Output is correct |
24 |
Correct |
7 ms |
444 KB |
Output is correct |
25 |
Correct |
7 ms |
444 KB |
Output is correct |
26 |
Correct |
6 ms |
696 KB |
Output is correct |
27 |
Correct |
7 ms |
696 KB |
Output is correct |
28 |
Correct |
7 ms |
696 KB |
Output is correct |
29 |
Correct |
6 ms |
952 KB |
Output is correct |
30 |
Correct |
6 ms |
696 KB |
Output is correct |
31 |
Correct |
16 ms |
948 KB |
Output is correct |
32 |
Correct |
24 ms |
952 KB |
Output is correct |
33 |
Correct |
32 ms |
696 KB |
Output is correct |
34 |
Correct |
36 ms |
944 KB |
Output is correct |
35 |
Correct |
45 ms |
940 KB |
Output is correct |
36 |
Correct |
23 ms |
704 KB |
Output is correct |
37 |
Correct |
55 ms |
692 KB |
Output is correct |
38 |
Correct |
40 ms |
948 KB |
Output is correct |
39 |
Correct |
42 ms |
952 KB |
Output is correct |
40 |
Correct |
37 ms |
708 KB |
Output is correct |
41 |
Correct |
39 ms |
856 KB |
Output is correct |
42 |
Correct |
25 ms |
956 KB |
Output is correct |
43 |
Correct |
51 ms |
932 KB |
Output is correct |
44 |
Correct |
38 ms |
944 KB |
Output is correct |
45 |
Correct |
31 ms |
948 KB |
Output is correct |
46 |
Correct |
29 ms |
952 KB |
Output is correct |
47 |
Correct |
28 ms |
948 KB |
Output is correct |
48 |
Correct |
44 ms |
708 KB |
Output is correct |
49 |
Correct |
31 ms |
696 KB |
Output is correct |
50 |
Correct |
34 ms |
704 KB |
Output is correct |
51 |
Correct |
42 ms |
700 KB |
Output is correct |
52 |
Correct |
37 ms |
696 KB |
Output is correct |
53 |
Correct |
51 ms |
700 KB |
Output is correct |
54 |
Correct |
38 ms |
952 KB |
Output is correct |
55 |
Correct |
37 ms |
688 KB |
Output is correct |
56 |
Correct |
43 ms |
696 KB |
Output is correct |
57 |
Correct |
45 ms |
944 KB |
Output is correct |
58 |
Correct |
44 ms |
1240 KB |
Output is correct |
59 |
Correct |
34 ms |
1200 KB |
Output is correct |
60 |
Correct |
33 ms |
952 KB |
Output is correct |