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"
const int MAX_N = 8192;
static int a[MAX_N];
int two[MAX_N];
int tri[MAX_N];
bool otn[MAX_N]; // i and i+1
void solve(int n) {
for( int i=1 ; i<n ; i++ ){
two[i] = query( i, i+1 );;
}
for( int i=1 ; i<n-1 ; i++ ){
tri[i] = query( i, i+2 );;
}
otn[1] = 1;
for( int i=1 ; i<n-1; i++ ){
if( tri[i] == two[i] + two[i+1] ) otn[i+1] = otn[i];
else otn[i+1] = !otn[i];
}
int min = 1, max = 1;
a[1] = 0;
for( int i=1 ; i<n ; i++ ){
if( otn[i] ) a[i+1] = a[i] - two[i];
else a[i+1] = a[i] + two[i];
if( a[min] > a[i] ) min = i;
if( a[max] < a[i] ) max = i;
}
/*
std::cerr<<" ! "<<min<<" "<<max<<" -> "<<a[min]<<" "<<a[max]<<"\n";
for( int i=1 ; i<=n ; i++ ) std::cerr<<a[i]<<" ";
std::cerr<<"\n";
*/
if( min < max ){
for( int i=1; i<=n ; i++ ){
answer( i, a[i] + 1 - a[min] );
}
return ;
}//else std::cerr<<" ne stava \n\n\n\n ";
min = 1, max = 1;
a[1] = 0;
for( int i=1 ; i<n ; i++ ){
if( otn[i] ) a[i+1] = a[i] + two[i];
else a[i+1] = a[i] - two[i];
if( a[min] > a[i] ) min = i;
if( a[max] < a[i] ) max = i;
}
/*
for( int i=1 ; i<=n ; i++ ) std::cerr<<a[i]<<" ";
std::cerr<<"\n";
*/
for( int i=1; i<=n ; i++ ){
answer( i, a[i] + 1 - a[min] );
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |