#include <bits/stdc++.h>
//#include "xylophone.h"
using namespace std;
//#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;
const int N=5007;
int a[N];
int p[N];
bool is[N];
void Set(int i,int x)
{
a[i]=x;
is[x]=1;
}
void answer(int i,int x)
{
cout<<i<<" "<<x<<endl;
}
int query(int l,int r)
{
cout<<l<<" "<<r<<endl;
int mx=-inf,mn=inf;
for(int i=l;i<=r;i++)
{
mx=max(mx,p[i]);
mn=min(mn,p[i]);
}
return mx-mn;
}
void solve(int n)
{
int l=1,r=n,sr,k;
while(l<=r)
{
sr=(l+r)/2;
if(query(sr,n)==n-1)
{
k=sr;
l=sr+1;
}
else r=sr-1;
}
cout<<k<<endl;
Set(k,1);
if(k+1<=n) Set(k+1,query(k,k+1)+1);
for(int i=k+2;i<=n;i++)
{
int d=query(i-1,i);
if(a[i-1]-d<1||is[a[i-1]-d]) Set(i,a[i-1]+d);
else if(a[i-1]+d>n||is[a[i-1]+d]) Set(i,a[i-1]-d);
else
{
int l=query(i-2,i);
if(l==max(d,abs(a[i-1]-a[i-2])))
{
if(a[i-2]<a[i-1]) Set(i,a[i-1]-d);
else Set(i,a[i-1]+d);
}
else
{
if(a[i-2]<a[i-1]) Set(i,a[i-1]+d);
else Set(i,a[i-1]-d);
}
}
}
if(k-1>0) Set(k-1,query(k-1,k)+1);
for(int i=k-2;i>0;i--)
{
int d=query(i,i+1);
if(a[i+1]-d<1||is[a[i+1]-d]) Set(i,a[i+1]+d);
else if(a[i+1]+d>n||is[a[i+1]+d]) Set(i,a[i+1]-d);
else
{
int l=query(i,i+2);
if(l==max(d,abs(a[i+1]-a[i+2])))
{
if(a[i+2]<a[i+1]) Set(i,a[i+1]-d);
else Set(i,a[i+1]+d);
}
else
{
if(a[i+2]<a[i+1]) Set(i,a[i+1]+d);
else Set(i,a[i+1]-d);
}
}
}
for(int i=1;i<=n;i++)
{
cout<<a[i]<<" ";
// answer(i,a[i]);
}
cout<<endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++) p[i]=i;
random_shuffle(p+1,p+n+1);
for(int i=1;i<=n;i++) cout<<p[i]<<" ";
cout<<endl;
solve(n);
return 0;
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:81:28: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
81 | if(k-1>0) Set(k-1,query(k-1,k)+1);
| ~~~~~^~~~~~~
/usr/bin/ld: /tmp/cctij0h2.o: in function `query(int, int)':
grader.cpp:(.text+0x0): multiple definition of `query(int, int)'; /tmp/cc4dVw53.o:xylophone.cpp:(.text+0xd0): first defined here
/usr/bin/ld: /tmp/cctij0h2.o: in function `answer(int, int)':
grader.cpp:(.text+0xa0): multiple definition of `answer(int, int)'; /tmp/cc4dVw53.o:xylophone.cpp:(.text+0x20): first defined here
/usr/bin/ld: /tmp/cctij0h2.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc4dVw53.o:xylophone.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status