#include <iostream>
#include "xylophone.h"
using namespace std;
const int MAXN = 1e5+5;
int pairs[MAXN];
int triplets[MAXN];
int ord[MAXN][4];
int ans[MAXN];
int solve(int n){
for(int i=1;i<n;i++){
pairs[i] = query(i,i+1);
}
for(int i=1;i<n-1;i++){
triplets[i] = query(i,i+2);
}
ord[1][1] = 1;
ord[1][0] = 0;
for(int i=1;i<n-1;i++){
if(triplets[i] == pairs[i]+pairs[i+1]){
ord[i+1][1] = ord[i][1];
ord[i+1][0] = ord[i][0];
}else{
ord[i+1][1] = !ord[i][1];
ord[i+1][0] = !ord[i][0];
}
}
ans[1] =1;
int holdmin = 0;
for(int i=2;i<=n;i++){
if(ord[i][0]){
ans[i] = ans[i-1]+pairs[i-1];
}else{
ans[i] = ans[i-1]-pairs[i-1];
}
holdmin = min(holdmin,ans[i]);
}
for(int i=1;i<=n;i++){
ans[i]+=holdmin;
}
bool ok = true;
for(int i=1;i<n-1;i++){
if(max(ans[i],max(ans[i+1],ans[i+2])) - min(ans[i],min(ans[i+1],ans[i+2]))!=triplets[i]){
ok = false;
break;
}
}
if(ok){
for(int i=1;i<=n;i++){
answer(i,ans[i]);
}
return 0;
}
ans[1] =1;
holdmin = 0;
for(int i=2;i<=n;i++){
if(ord[i][1]){
ans[i] = ans[i-1]+pairs[i-1];
}else{
ans[i] = ans[i-1]-pairs[i-1];
}
holdmin = min(holdmin,ans[i]);
}
for(int i=1;i<=n;i++){
ans[i]+=holdmin;
}
ok = true;
for(int i=1;i<n-1;i++){
if(max(ans[i],max(ans[i+1],ans[i+2])) - min(ans[i],min(ans[i+1],ans[i+2]))!=triplets[i]){
ok = false;
break;
}
}
for(int i=1;i<=n;i++){
answer(i,ans[i]);
}
}
Compilation message
xylophone.cpp: In function 'int solve(int)':
xylophone.cpp:9:5: error: ambiguating new declaration of 'int solve(int)'
int solve(int n){
^~~~~
In file included from xylophone.cpp:2:0:
xylophone.h:3:6: note: old declaration 'void solve(int)'
void solve(int N);
^~~~~
xylophone.cpp:79:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^