#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
void solve(int n){
int ind1,l=1,r=n;
while(l<=r){
int mid=(l+r)/2;
int x=query(mid,n);
if (x==n-1) {
ind1=mid;
l=mid+1;
}else{
r=mid-1;
}
}
int indn;
l=ind1+1;
r=n;
while(l<=r){
int mid=(l+r)/2;
int x=query(ind1,mid);
if (x==n-1) {
indn=mid;
r=mid-1;
}else{
l=mid+1;
}
}
vector<int> vis(n+1),ans(n+1);
vis[1]=1;
vis[n]=1;
ans[id1]=1;
ans[idn]=n;
for(int i=id1-1;i>=1;i--){
int q=query(i,i+1);
int a=ans[i+1]+x;
int b=ans[i+1]-x;
if(b<=0 || vis[b]==1){
ans[i]=a;
vis[a]=1;
}else if(a>n || vis[a]==1){
ans[i]=b;
vis[b]=1;
}else{
int x=query(i,i+2);
int mx=max(a,max(ans[i+1],ans[i+2]));
int mn=min(a,min(ans[i+1],ans[i+2]));
if(x==mx-mn){
ans[i]=a;
vis[a]=1;
}else{
ans[i]=b;
vis[b]=1;
}
}
}
for(int i=idn-1;i>id1;i--){
int q=query(i,i+1);
int a=ans[i+1]+x;
int b=ans[i+1]-x;
if(b<=0 || vis[b]==1){
ans[i]=a;
vis[a]=1;
}else if(a>n || vis[a]==1){
ans[i]=b;
vis[b]=1;
}else{
int x=query(i,i+2);
int mx=max(a,max(ans[i+1],ans[i+2]));
int mn=min(a,min(ans[i+1],ans[i+2]));
if(x==mx-mn){
ans[i]=a;
vis[a]=1;
}else{
ans[i]=b;
vis[b]=1;
}
}
}
for(int i=idn+1;i<=n;i++){
int q=query(i,i-1);
int a=ans[i-1]+x;
int b=ans[i-1]-x;
if(b<=0 || vis[b]==1){
ans[i]=a;
vis[a]=1;
}else if(a>n || vis[a]==1){
ans[i]=b;
vis[b]=1;
}else{
int x=query(i,i-2);
int mx=max(a,max(ans[i-1],ans[i-2]));
int mn=min(a,min(ans[i-1],ans[i-2]));
if(x==mx-mn){
ans[i]=a;
vis[a]=1;
}else{
ans[i]=b;
vis[b]=1;
}
}
}
for(int i=1;i<=n;i++) answer(i,ans[i]);
}
Compilation message
xylophone.cpp: In function 'void solve(long long int)':
xylophone.cpp:40:6: error: 'id1' was not declared in this scope; did you mean 'ind1'?
40 | ans[id1]=1;
| ^~~
| ind1
xylophone.cpp:41:6: error: 'idn' was not declared in this scope; did you mean 'indn'?
41 | ans[idn]=n;
| ^~~
| indn
xylophone.cpp:46:18: error: 'x' was not declared in this scope
46 | int a=ans[i+1]+x;
| ^
xylophone.cpp:44:7: warning: unused variable 'q' [-Wunused-variable]
44 | int q=query(i,i+1);
| ^
xylophone.cpp:72:18: error: 'x' was not declared in this scope
72 | int a=ans[i+1]+x;
| ^
xylophone.cpp:70:7: warning: unused variable 'q' [-Wunused-variable]
70 | int q=query(i,i+1);
| ^
xylophone.cpp:98:18: error: 'x' was not declared in this scope
98 | int a=ans[i-1]+x;
| ^
xylophone.cpp:96:7: warning: unused variable 'q' [-Wunused-variable]
96 | int q=query(i,i-1);
| ^