This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std ;
void solve(int N) {
int A[N+2] = {0} , vis[N+2] = {0} , low = 1 , high = N ;
int k;
int lo=1;
int hi=N;
while(lo<=hi)
{
int mid=lo+hi>>1;
if(query(mid,N)==N-1)
{
lo=mid+1;
}
else
{
k=mid;
hi=mid-1;
}
}
low = k - 1 ;
A[low] = 1 , vis[1] = 1 ;
for(int i = low - 1 ; i >= 1 ; --i)
{
int temp = query(i,i+1) , left = A[i+1] - temp , right = A[i+1] + temp ;
if((left<=0) || vis[left])
{
vis[right] = 1 ;
A[i] = right ;
}
else if((right>N) || vis[right])
{
vis[left] = 1 ;
A[i] = left ;
}
else
{
temp = query(i,i+2) ;
if((max(left,A[i+2])-min(A[i+1],A[i+2]))==temp)
{
vis[left] = 1 ;
A[i] = left ;
}
else
{
vis[right] = 1 ;
A[i] = right ;
}
}
}
for(int i = low + 1 ; i <= N ; ++i)
{
int temp = query(i-1,i) , left = A[i-1] - temp , right = A[i-1] + temp ;
if((left<=0) || vis[left])
{
vis[right] = 1 ;
A[i] = right ;
}
else if((right>N) || vis[right])
{
vis[left] = 1 ;
A[i] = left ;
}
else
{
temp = query(i-2,i) ;
if((max(left,A[i-2])-min(A[i-1],A[i-2]))==temp)
{
vis[left] = 1 ;
A[i] = left ;
}
else
{
vis[right] = 1 ;
A[i] = right ;
}
}
}
for(int i = 1; i <= N; i++)
{
answer(i, A[i]) ;
}
}
Compilation message (stderr)
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:13:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
13 | int mid=lo+hi>>1;
| ~~^~~
xylophone.cpp:7:48: warning: unused variable 'high' [-Wunused-variable]
7 | int A[N+2] = {0} , vis[N+2] = {0} , low = 1 , high = N ;
| ^~~~
xylophone.cpp:8:6: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
8 | int k;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |