#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
int n;
int a1;
int arr[10000 + 5];
int vis[10000 + 5];
int ok(int x)
{
if (x < 1 || x > n)
return 0;
return !vis[x];
}
void conLhs()
{
if (a1 > 1)
arr[a1 - 1] = query(a1 - 1, a1) + 1;
for (int i = a1 - 2; i > 0; --i)
{
int q1 = query(i, i + 1);
if (ok(arr[i + 1] + q1) + ok(arr[i + 1] - q1) == 1)
{
arr[i] = ok(arr[i + 1] + q1) ? arr[i + 1] + q1 : arr[i + 1] - q1;
vis[arr[i]] = 1;
continue;
}
int q2 = abs(arr[i + 1] - arr[i + 2]);
int q3 = query(i, i + 2);
int sgn = ((q1 + q2 == q3 && arr[i + 1] > arr[i + 2]) ||
(arr[i + 1] < arr[i + 2] && q1 + q2 != q3)
? 1
: -1);
arr[i] = arr[i + 1] + q1 * sgn;
vis[arr[i]] = 1;
}
}
void conMhs()
{
if (a1 + 1 <= n)
arr[a1 + 1] = query(a1, a1 + 1) + 1;
for (int i = a1 + 2; i <= n; ++i)
{
int q1 = query(i - 1, i);
if (ok(arr[i - 1] + q1) + ok(arr[i - 1] - q1) == 1)
{
arr[i] = ok(arr[i - 1] + q1) ? arr[i - 1] + q1 : arr[i - 1] - q1;
vis[arr[i]] = 1;
continue;
}
int q2 = abs(arr[i - 1] - arr[i - 2]);
int q3 = query(i - 2, i);
int sgn = ((q1 + q2 == q3 && arr[i - 1] > arr[i - 2]) ||
(arr[i - 1] < arr[i - 2] && q1 + q2 != q3)
? 1
: -1);
arr[i] = arr[i - 1] + q1 * sgn;
vis[arr[i]] = 1;
}
}
void solve(int N)
{
n = N;
int l = 1, r = N;
vis[1] = 1;
while (l <= r)
{
int mid = (l + r) >> 1;
if (query(mid, N) == N - 1)
{
a1 = mid;
l = mid + 1;
}
else
r = mid - 1;
}
arr[a1] = 1;
conLhs();
conMhs();
for (int i = 1; i <= N; ++i)
{
answer(i, arr[i]);
//printf("%d ", arr[i]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
4 ms |
364 KB |
Output is correct |
17 |
Correct |
6 ms |
364 KB |
Output is correct |
18 |
Correct |
16 ms |
364 KB |
Output is correct |
19 |
Correct |
17 ms |
364 KB |
Output is correct |
20 |
Correct |
17 ms |
364 KB |
Output is correct |
21 |
Correct |
12 ms |
384 KB |
Output is correct |
22 |
Correct |
7 ms |
388 KB |
Output is correct |
23 |
Correct |
12 ms |
364 KB |
Output is correct |
24 |
Correct |
9 ms |
364 KB |
Output is correct |
25 |
Correct |
10 ms |
364 KB |
Output is correct |
26 |
Correct |
16 ms |
364 KB |
Output is correct |
27 |
Correct |
16 ms |
620 KB |
Output is correct |
28 |
Correct |
12 ms |
396 KB |
Output is correct |
29 |
Correct |
12 ms |
364 KB |
Output is correct |
30 |
Correct |
16 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
4 ms |
364 KB |
Output is correct |
17 |
Correct |
6 ms |
364 KB |
Output is correct |
18 |
Correct |
16 ms |
364 KB |
Output is correct |
19 |
Correct |
17 ms |
364 KB |
Output is correct |
20 |
Correct |
17 ms |
364 KB |
Output is correct |
21 |
Correct |
12 ms |
384 KB |
Output is correct |
22 |
Correct |
7 ms |
388 KB |
Output is correct |
23 |
Correct |
12 ms |
364 KB |
Output is correct |
24 |
Correct |
9 ms |
364 KB |
Output is correct |
25 |
Correct |
10 ms |
364 KB |
Output is correct |
26 |
Correct |
16 ms |
364 KB |
Output is correct |
27 |
Correct |
16 ms |
620 KB |
Output is correct |
28 |
Correct |
12 ms |
396 KB |
Output is correct |
29 |
Correct |
12 ms |
364 KB |
Output is correct |
30 |
Correct |
16 ms |
364 KB |
Output is correct |
31 |
Correct |
28 ms |
396 KB |
Output is correct |
32 |
Correct |
45 ms |
364 KB |
Output is correct |
33 |
Correct |
53 ms |
364 KB |
Output is correct |
34 |
Correct |
58 ms |
364 KB |
Output is correct |
35 |
Correct |
88 ms |
364 KB |
Output is correct |
36 |
Correct |
65 ms |
400 KB |
Output is correct |
37 |
Correct |
54 ms |
528 KB |
Output is correct |
38 |
Correct |
63 ms |
364 KB |
Output is correct |
39 |
Correct |
90 ms |
484 KB |
Output is correct |
40 |
Correct |
55 ms |
364 KB |
Output is correct |
41 |
Correct |
78 ms |
364 KB |
Output is correct |
42 |
Correct |
64 ms |
364 KB |
Output is correct |
43 |
Correct |
48 ms |
364 KB |
Output is correct |
44 |
Correct |
63 ms |
484 KB |
Output is correct |
45 |
Correct |
73 ms |
484 KB |
Output is correct |
46 |
Correct |
60 ms |
364 KB |
Output is correct |
47 |
Correct |
81 ms |
364 KB |
Output is correct |
48 |
Correct |
63 ms |
364 KB |
Output is correct |
49 |
Correct |
64 ms |
484 KB |
Output is correct |
50 |
Correct |
89 ms |
484 KB |
Output is correct |
51 |
Correct |
53 ms |
364 KB |
Output is correct |
52 |
Correct |
78 ms |
364 KB |
Output is correct |
53 |
Correct |
63 ms |
364 KB |
Output is correct |
54 |
Correct |
84 ms |
612 KB |
Output is correct |
55 |
Correct |
65 ms |
536 KB |
Output is correct |
56 |
Correct |
58 ms |
480 KB |
Output is correct |
57 |
Correct |
62 ms |
364 KB |
Output is correct |
58 |
Correct |
66 ms |
540 KB |
Output is correct |
59 |
Correct |
77 ms |
484 KB |
Output is correct |
60 |
Correct |
79 ms |
364 KB |
Output is correct |