#include<bits/stdc++.h>
#include "xylophone.h"
using namespace std;
typedef long long ll;
const ll INF=1e18;
const int maxn=1e6+5;
const int mod=1e9+7;
const int mo=998244353;
using pi=pair<ll,ll>;
using vi=vector<ll>;
using pii=pair<pair<ll,ll>,ll>;
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define eb emplace_back
#define PI 3.14159265359
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
int n;
int a[5005];
int ok[10005];
void solve(int n){
int l=1;
int r=n;
int pos;
while(l<=r){
int mid=(l+r)/2;
if(query(mid,n)>=n-1){
pos=mid;
l=mid+1;
}
else{
r=mid-1;
}
}
a[pos]=1;
if(pos>1){
a[pos-1]=1+query(pos-1,pos);
ok[a[pos-1]]=1;
ok[1]=1;
for(int i=pos-2;i>=1;i--){
int hieu=query(i,i+1);
if(a[i+1]+hieu>n || ok[a[i+1]+hieu]==1){
a[i]=a[i+1]-hieu;
ok[a[i]]=1;
continue;
}
if(a[i+1]-hieu<1 || ok[a[i+1]-hieu]==1){
a[i]=a[i+1]+hieu;
ok[a[i]]=1;
continue;
}
int hieumoi=query(i,i+2);
if(a[i+1]>a[i+2]){
if(hieumoi==a[i+1]-a[i+2]){
a[i]=a[i+1]-hieu;
}
if(hieumoi==hieu+a[i+1]-a[i+2]){
a[i]=a[i+1]+hieu;
}
else if(hieumoi==hieu){
a[i]=a[i+1]-hieu;
}
}
else{
if(hieumoi==a[i+2]-a[i+1]){
a[i]=a[i+1]+hieu;
}
if(hieumoi==hieu){
a[i]=a[i+1]+hieu;
}
if(hieumoi==hieu+a[i+2]-a[i+1]){
a[i]=a[i+1]-hieu;
}
}
ok[a[i]]=1;
}
}
if(pos<n){
a[pos+1]=1+query(pos,pos+1);
ok[a[pos+1]]=1;
for(int i=pos+2;i<=n;i++){
int hieu=query(i-1,i);
if(a[i-1]+hieu>n || ok[a[i-1]+hieu]==1){
a[i]=a[i-1]-hieu;
ok[a[i]]=1;
continue;
}
if(a[i-1]-hieu<1 || ok[a[i-1]-hieu]==1){
a[i]=a[i-1]+hieu;
ok[a[i]]=1;
continue;
}
int hieumoi=query(i-2,i);
if(a[i-1]>a[i-2]){
if(hieumoi==a[i-1]-a[i-2]){
a[i]=a[i-1]-hieu;
}
if(hieumoi==hieu+a[i-1]-a[i-2]){
a[i]=a[i-1]+hieu;
}
if(hieumoi==hieu){
a[i]=a[i-1]-hieu;
}
}
else{
if(hieumoi==a[i-2]-a[i-1]){
a[i]=a[i-1]+hieu;
}
if(hieumoi==hieu){
a[i]=a[i-1]+hieu;
}
if(hieumoi==hieu+a[i-2]-a[i-1]){
a[i]=a[i-1]-hieu;
}
}
ok[a[i]]=1;
}
}
for(int i=1;i<=n;i++){
answer(i,a[i]);
}
return;
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:28:6: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
28 | int pos;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
3 ms |
300 KB |
Output is correct |
18 |
Correct |
10 ms |
308 KB |
Output is correct |
19 |
Correct |
13 ms |
208 KB |
Output is correct |
20 |
Correct |
14 ms |
208 KB |
Output is correct |
21 |
Correct |
9 ms |
312 KB |
Output is correct |
22 |
Correct |
10 ms |
312 KB |
Output is correct |
23 |
Correct |
10 ms |
208 KB |
Output is correct |
24 |
Correct |
10 ms |
304 KB |
Output is correct |
25 |
Correct |
10 ms |
208 KB |
Output is correct |
26 |
Correct |
14 ms |
208 KB |
Output is correct |
27 |
Correct |
9 ms |
208 KB |
Output is correct |
28 |
Correct |
9 ms |
208 KB |
Output is correct |
29 |
Correct |
12 ms |
208 KB |
Output is correct |
30 |
Correct |
12 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
3 ms |
300 KB |
Output is correct |
18 |
Correct |
10 ms |
308 KB |
Output is correct |
19 |
Correct |
13 ms |
208 KB |
Output is correct |
20 |
Correct |
14 ms |
208 KB |
Output is correct |
21 |
Correct |
9 ms |
312 KB |
Output is correct |
22 |
Correct |
10 ms |
312 KB |
Output is correct |
23 |
Correct |
10 ms |
208 KB |
Output is correct |
24 |
Correct |
10 ms |
304 KB |
Output is correct |
25 |
Correct |
10 ms |
208 KB |
Output is correct |
26 |
Correct |
14 ms |
208 KB |
Output is correct |
27 |
Correct |
9 ms |
208 KB |
Output is correct |
28 |
Correct |
9 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 |
27 ms |
296 KB |
Output is correct |
32 |
Correct |
41 ms |
308 KB |
Output is correct |
33 |
Correct |
51 ms |
312 KB |
Output is correct |
34 |
Correct |
49 ms |
336 KB |
Output is correct |
35 |
Correct |
55 ms |
328 KB |
Output is correct |
36 |
Correct |
39 ms |
304 KB |
Output is correct |
37 |
Correct |
44 ms |
324 KB |
Output is correct |
38 |
Correct |
55 ms |
316 KB |
Output is correct |
39 |
Correct |
60 ms |
328 KB |
Output is correct |
40 |
Correct |
50 ms |
328 KB |
Output is correct |
41 |
Correct |
68 ms |
328 KB |
Output is correct |
42 |
Correct |
48 ms |
328 KB |
Output is correct |
43 |
Correct |
41 ms |
308 KB |
Output is correct |
44 |
Correct |
46 ms |
308 KB |
Output is correct |
45 |
Correct |
26 ms |
304 KB |
Output is correct |
46 |
Correct |
57 ms |
312 KB |
Output is correct |
47 |
Correct |
61 ms |
448 KB |
Output is correct |
48 |
Correct |
67 ms |
320 KB |
Output is correct |
49 |
Correct |
54 ms |
328 KB |
Output is correct |
50 |
Correct |
26 ms |
308 KB |
Output is correct |
51 |
Correct |
62 ms |
308 KB |
Output is correct |
52 |
Correct |
59 ms |
340 KB |
Output is correct |
53 |
Correct |
54 ms |
440 KB |
Output is correct |
54 |
Correct |
53 ms |
316 KB |
Output is correct |
55 |
Correct |
59 ms |
308 KB |
Output is correct |
56 |
Correct |
54 ms |
348 KB |
Output is correct |
57 |
Correct |
62 ms |
328 KB |
Output is correct |
58 |
Correct |
61 ms |
328 KB |
Output is correct |
59 |
Correct |
63 ms |
320 KB |
Output is correct |
60 |
Correct |
49 ms |
332 KB |
Output is correct |