#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
void solve(int n){
bool have[n+1]={0};
int a[n+1]={0};
int mn;
int l=1;
int r=n-1;
while(l<=r){
int s=(l+r)/2;
if(query(s+1, n)==n-1){
l=s+1;
}
else{
r=s-1;
}
}
mn=l;
have[1]=1;
int nxt=1+query(mn, mn+1);
a[mn]=1;
a[mn+1]=nxt;
have[nxt]=1;
if(mn!=1){
int prv=1+query(mn-1, mn);
a[mn-1]=prv;
have[prv]=1;
}
for(int i=mn-2; i>=1; i--){
int q1=query(i, i+1);
int pos1=a[i+1]+q1;
int pos2=a[i+1]-q1;
if(pos1<=0 || pos1>n || have[pos1]){
a[i]=pos2;
}
else if(pos2<=0 || pos2>n || have[pos2]){
a[i]=pos1;
}
else{
int q2=query(i, i+2);
if(q2==q1 || q2==abs(a[i+1]-a[i+2])){
if(a[i+1]>a[i+2]){
a[i]=pos2;
}
else{
a[i]=pos1;
}
}
else{
if(a[i+1]>a[i+2]){
a[i]=pos1;
}
else a[i]=pos2;
}
}
}
for(int i=mn+2; i<=n; i++){
int q1=query(i-1, i);
int pos1=a[i-1]+q1;
int pos2=a[i-1]-q1;
if(pos1<=0 || pos1>n || have[pos1]){
a[i]=pos2;
}
else if(pos2<=0 || pos2>n || have[pos2]){
a[i]=pos1;
}
else{
int q2=query(i-2, i);
if(q2==q1 || q2==abs(a[i-1]-a[i-2])){
if(a[i-1]>a[i-2]){
a[i]=pos2;
}
else{
a[i]=pos1;
}
}
else{
if(a[i-1]>a[i-2]){
a[i]=pos1;
}
else a[i]=pos2;
}
}
}
for(int i=1; i<=n; i++){
answer(i, a[i]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
3 ms |
344 KB |
Output is correct |
18 |
Correct |
6 ms |
344 KB |
Output is correct |
19 |
Correct |
6 ms |
444 KB |
Output is correct |
20 |
Correct |
8 ms |
436 KB |
Output is correct |
21 |
Correct |
6 ms |
440 KB |
Output is correct |
22 |
Correct |
6 ms |
344 KB |
Output is correct |
23 |
Correct |
7 ms |
440 KB |
Output is correct |
24 |
Correct |
6 ms |
344 KB |
Output is correct |
25 |
Correct |
6 ms |
344 KB |
Output is correct |
26 |
Correct |
7 ms |
436 KB |
Output is correct |
27 |
Correct |
7 ms |
344 KB |
Output is correct |
28 |
Correct |
6 ms |
440 KB |
Output is correct |
29 |
Correct |
5 ms |
436 KB |
Output is correct |
30 |
Correct |
6 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
3 ms |
344 KB |
Output is correct |
18 |
Correct |
6 ms |
344 KB |
Output is correct |
19 |
Correct |
6 ms |
444 KB |
Output is correct |
20 |
Correct |
8 ms |
436 KB |
Output is correct |
21 |
Correct |
6 ms |
440 KB |
Output is correct |
22 |
Correct |
6 ms |
344 KB |
Output is correct |
23 |
Correct |
7 ms |
440 KB |
Output is correct |
24 |
Correct |
6 ms |
344 KB |
Output is correct |
25 |
Correct |
6 ms |
344 KB |
Output is correct |
26 |
Correct |
7 ms |
436 KB |
Output is correct |
27 |
Correct |
7 ms |
344 KB |
Output is correct |
28 |
Correct |
6 ms |
440 KB |
Output is correct |
29 |
Correct |
5 ms |
436 KB |
Output is correct |
30 |
Correct |
6 ms |
344 KB |
Output is correct |
31 |
Correct |
17 ms |
444 KB |
Output is correct |
32 |
Correct |
20 ms |
448 KB |
Output is correct |
33 |
Correct |
35 ms |
432 KB |
Output is correct |
34 |
Correct |
36 ms |
436 KB |
Output is correct |
35 |
Correct |
37 ms |
448 KB |
Output is correct |
36 |
Incorrect |
45 ms |
344 KB |
Wrong Answer [2] |
37 |
Halted |
0 ms |
0 KB |
- |