QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#302850 | #6303. Inversion | ZYF_B# | TL | 0ms | 0kb | C++14 | 1.0kb | 2024-01-11 14:10:40 | 2024-01-11 14:10:40 |
answer
#include<bits/stdc++.h>
#define ll long long
#define re register
#define INF 2147483647
using namespace std;
inline int read()
{
int f=1,x=0;char s=getchar();
while(s<'0'||s>'9')
{
if(s=='-') f=-1;
s=getchar();
}
while(s>='0'&&s<='9')
{
x=x*10+s-48;
s=getchar();
}
return f*x;
}
const int N=2005;
int n;
int mp[N][N],v[N],p[N];
int query(int l,int r)
{
if(l>=r) return 0;
if(mp[l][r]!=-1) return mp[l][r];
printf("? %d %d\n",l,r);
cout.flush();
int x;
cin>>x;
return mp[l][r]=x;
}
int ask(int x,int y)
{
return query(x,y)^query(x+1,y-1)^query(x,y-1)^query(x+1,y);
}
int main()
{
memset(mp,-1,sizeof(mp));
cin>>n;
v[1]=1;
for(int i=2;i<=n;i++)
{
int l=1,r=i-1,pos=-1;
while(l<=r)
{
int mid=(l+r)>>1;
if(ask(v[mid],i)) pos=mid,r=mid-1;
else l=mid;
}
for(int j=i-1;j>=pos;j--) v[j+1]=v[j];
v[pos]=i;
}
printf("! ");
for(int i=1;i<=n;i++) p[v[i]]=i;
for(int i=1;i<=n;i++) printf("%d ",p[i]);
cout.flush();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
3 0
output:
? 1 2