#include "xylophone.h"
using namespace std;
const int MN=5e3+5;
int arr[MN];
void solve(int N){
int n=N;
int l=1,r=n-1;
while(l<r){
int mid=l+r>>1;
int res=query(mid,n);
// cout<<"Case "<<mid<<' '<<n<<": "<<res<<'\n';
if(res==n-1) l=mid+1;
else r=mid;
}
int idx=l-1;
answer(idx,1);
l=idx-2; r=idx+2;
if(idx>1){
int res=query(idx-1,idx);
answer(idx-1,res+1);
}
int res=query(idx,idx+1);
answer(idx+1,res+1);
for(int i=l;i>=1;--i){
int res=query(i,i+1);
int res2=query(i,i+2);
if(res==res2){
if(arr[i+2]<arr[i+1]) arr[i]=arr[i+1]-res;
else arr[i]=arr[i+1]+res;
}
else{
if(arr[i+1]>arr[i+2]){
if(res2==arr[i+1]-arr[i+2]) arr[i]=arr[i+1]-res;
else arr[i]=arr[i+1]+res;
}
else{
if(res2==arr[i+2]-arr[i+1]) arr[i]=arr[i+1]+res;
else arr[i]=arr[i+1]-res;
}
}
answer(i,arr[i]);
}
for(int i=r;i<=n;++i){
int res2=query(i-2,i);
// cout<<"Case "<<i<<": "<<res<<' '<<res2<<'\n';
if(res==res2){
if(arr[i-2]<arr[i-1]) arr[i]=arr[i-1]-res;
else arr[i]=arr[i-1]+res;
}
else{
if(arr[i-2]<arr[i-1]){
if(res2==arr[i-1]-arr[i-2]) arr[i]=arr[i-1]-res;
else arr[i]=arr[i-1]+res;
}
else{
if(res2==arr[i-2]-arr[i-1]) arr[i]=arr[i-1]+res;
else arr[i]=arr[i-1]-res;
}
}
answer(i,arr[i]);
}
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:12:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
12 | int mid=l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Wrong Answer [3] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Wrong Answer [3] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Wrong Answer [3] |
2 |
Halted |
0 ms |
0 KB |
- |