#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
namespace interact{
void A(int pos, int val){
// cout << pos << ": " << val+1 << endl;
answer(pos+1, val+1);
// cout << "FIN" << endl;
}
int Q(int l, int r){
return query(l+1, r+1);
}
};
int find_n(int n){
int l = 0, r = n-1;
int last = interact::Q(0, n-1);
while (l < r){
int m = (l+r)>>1;
int q = interact::Q(0, m);
if (last == q){
r = m;
}
else{
l = m+1;
}
}
// cout << "P: " << l << endl;
return l;
}
void solve(int n){
vector<bool> a(n);
int posmax = find_n(n);
interact::A(posmax, n-1);
int last = n-1, last1;
a.back() = 1;
for (int i=posmax-1; i>=0; i--){
int cdelta = interact::Q(i, i+1);
int first = last - cdelta;
int second = last + cdelta;
int realval;
if (first < 0 || a[first]){
realval = second;
}
else if (second >= n || a[second]){
realval = first;
}
else{
int cdelta1 = interact::Q(i, i+2);
if (cdelta1 == cdelta + abs(last - last1)){
// last1 -> last -> i
if (last1 > last){
// last > i
realval = first;
}
else{
realval = second;
}
}
else{
if (last1 < last){
realval = first;
}
else{
realval = second;
}
}
}
interact::A(i, realval);
last1 = last;
last = realval;
a[realval] = true;
}
last = n-1;
for (int i=posmax+1; i<n; i++){
int cdelta = interact::Q(i-1, i);
int first = last - cdelta;
int second = last + cdelta;
int realval;
if (first < 0 || a[first]){
realval = second;
}
else if (second >= n || a[second]){
realval = first;
}
else{
int cdelta1 = interact::Q(i-2, i);
if (cdelta1 == cdelta + abs(last - last1)){
// last1 -> last -> i
if (last1 > last){
// last > i
realval = first;
}
else{
realval = second;
}
}
else{
if (last1 < last){
realval = first;
}
else{
realval = second;
}
}
}
interact::A(i, realval);
last1 = last;
last = realval;
a[realval] = true;
}
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:52:5: warning: 'last1' may be used uninitialized in this function [-Wmaybe-uninitialized]
52 | if (last1 > last){
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
2 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
2 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
2 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
2 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
3 ms |
208 KB |
Output is correct |
17 |
Correct |
8 ms |
208 KB |
Output is correct |
18 |
Correct |
14 ms |
208 KB |
Output is correct |
19 |
Correct |
10 ms |
208 KB |
Output is correct |
20 |
Correct |
12 ms |
208 KB |
Output is correct |
21 |
Correct |
12 ms |
208 KB |
Output is correct |
22 |
Correct |
10 ms |
208 KB |
Output is correct |
23 |
Correct |
9 ms |
208 KB |
Output is correct |
24 |
Correct |
9 ms |
208 KB |
Output is correct |
25 |
Correct |
11 ms |
208 KB |
Output is correct |
26 |
Correct |
15 ms |
208 KB |
Output is correct |
27 |
Correct |
14 ms |
208 KB |
Output is correct |
28 |
Correct |
11 ms |
208 KB |
Output is correct |
29 |
Correct |
12 ms |
208 KB |
Output is correct |
30 |
Correct |
12 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
2 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
2 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
3 ms |
208 KB |
Output is correct |
17 |
Correct |
8 ms |
208 KB |
Output is correct |
18 |
Correct |
14 ms |
208 KB |
Output is correct |
19 |
Correct |
10 ms |
208 KB |
Output is correct |
20 |
Correct |
12 ms |
208 KB |
Output is correct |
21 |
Correct |
12 ms |
208 KB |
Output is correct |
22 |
Correct |
10 ms |
208 KB |
Output is correct |
23 |
Correct |
9 ms |
208 KB |
Output is correct |
24 |
Correct |
9 ms |
208 KB |
Output is correct |
25 |
Correct |
11 ms |
208 KB |
Output is correct |
26 |
Correct |
15 ms |
208 KB |
Output is correct |
27 |
Correct |
14 ms |
208 KB |
Output is correct |
28 |
Correct |
11 ms |
208 KB |
Output is correct |
29 |
Correct |
12 ms |
208 KB |
Output is correct |
30 |
Correct |
12 ms |
208 KB |
Output is correct |
31 |
Correct |
26 ms |
208 KB |
Output is correct |
32 |
Correct |
35 ms |
208 KB |
Output is correct |
33 |
Correct |
58 ms |
208 KB |
Output is correct |
34 |
Correct |
60 ms |
208 KB |
Output is correct |
35 |
Correct |
27 ms |
208 KB |
Output is correct |
36 |
Correct |
49 ms |
208 KB |
Output is correct |
37 |
Correct |
56 ms |
208 KB |
Output is correct |
38 |
Correct |
52 ms |
208 KB |
Output is correct |
39 |
Correct |
69 ms |
208 KB |
Output is correct |
40 |
Correct |
55 ms |
208 KB |
Output is correct |
41 |
Correct |
68 ms |
208 KB |
Output is correct |
42 |
Correct |
54 ms |
208 KB |
Output is correct |
43 |
Correct |
54 ms |
208 KB |
Output is correct |
44 |
Correct |
51 ms |
208 KB |
Output is correct |
45 |
Correct |
58 ms |
208 KB |
Output is correct |
46 |
Correct |
59 ms |
208 KB |
Output is correct |
47 |
Correct |
72 ms |
208 KB |
Output is correct |
48 |
Correct |
70 ms |
208 KB |
Output is correct |
49 |
Correct |
31 ms |
208 KB |
Output is correct |
50 |
Correct |
57 ms |
208 KB |
Output is correct |
51 |
Correct |
69 ms |
208 KB |
Output is correct |
52 |
Correct |
59 ms |
208 KB |
Output is correct |
53 |
Correct |
63 ms |
208 KB |
Output is correct |
54 |
Correct |
50 ms |
208 KB |
Output is correct |
55 |
Correct |
55 ms |
208 KB |
Output is correct |
56 |
Correct |
46 ms |
208 KB |
Output is correct |
57 |
Correct |
56 ms |
208 KB |
Output is correct |
58 |
Correct |
69 ms |
208 KB |
Output is correct |
59 |
Correct |
67 ms |
208 KB |
Output is correct |
60 |
Correct |
66 ms |
208 KB |
Output is correct |