QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#360546 | #6303. Inversion | Siilhouette | WA | 0ms | 19688kb | C++14 | 1.9kb | 2024-03-21 21:26:00 | 2024-03-21 21:26:00 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS
#include<queue>
#include<cmath>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=2010;
int n,tot,cnt,tim,v[N],ans[N][N],a[N],c[N];
//struct Node{int l,r;}a[N];
inline bool ask(int l,int r)
{
if(l==r)return 0;
int res;
printf("? %d %d\n",l,r);
cout.flush();
scanf("%d",&res);
return ans[l][r]=res;
}
inline bool query(int l,int r)
{
//cout<<"query "<<l<<" "<<r<<endl;
//cout<<"ans "<<ans[l][r]<<endl;
if(l==r)return 0;
if(l+1==r)return (~ans[l][r])?ans[l][r]:ask(l,r);
int x=(~ans[l][r])?ans[l][r]:ask(l,r);
int y=(~ans[l+1][r])?ans[l+1][r]:ask(l+1,r);
int z=(~ans[l][r-1])?ans[l][r-1]:ask(l,r-1);
int w=(~ans[l+1][r-1])?ans[l+1][r-1]:ask(l+1,r-1);
return x^y^z^w;
}
inline void insert(int x,int d)
{
for(int i=cnt;i>=d;i--)
a[i+1]=a[i];
a[d]=x;
cnt++;tim++;
for(int i=d+1;i<=cnt;i++)
v[a[i]]=tim;
for(int i=x-1,pos=0;i;i--)
{
if(v[i]==tim)pos^=1;
ans[i][x]=ans[i][x-1]^pos;
}
cout<<"insert "<<endl;
for(int i=1;i<=cnt;i++)
cout<<a[i]<<" ";
cout<<endl;
cout<<"x "<<endl;
for(int i=1;i<=x;i++)
cout<<ans[i][x]<<" ";
cout<<endl;
/**/
}
int main()
{
int pos;
memset(ans,-1,sizeof(ans));
scanf("%d",&n);
for(int i=1;i<=n;i++)ans[i][i]=0;
pos=ask(1,2);
insert(1,1);
insert(2,pos?1:2);
for(int i=3;i<=n;i++)
{
/*
if(query(a[1],i)){
//cout<<"!"<<endl;
insert(i,1);continue; }
if(!query(a[cnt],i)){
//cout<<"#"<<endl;
insert(i,cnt+1);continue; }
*/
int l=1,r=cnt;
while(l<r)
{
int mid=l+r>>1;
if(query(a[mid],i))r=mid;
else l=mid+1;
}
if(l==cnt)insert(i,query(a[cnt],i)?cnt:cnt+1);
else insert(i,l);
}
for(int i=1;i<=n;i++)
c[a[i]]=i;
putchar('!');
for(int i=1;i<=n;i++)
printf(" %d",c[i]);
putchar('\n');
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 19688kb
input:
3 0
output:
? 1 2 insert 1 x 0 insert 1 2 x 0 0 ? 1 3
result:
wrong output format Unexpected end of file - int32 expected