QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#302871 | #6303. Inversion | ZYF_B# | WA | 55ms | 19276kb | C++14 | 1.2kb | 2024-01-11 14:29:30 | 2024-01-11 14:29:31 |
Judging History
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],suf[N];
int query(int l,int r)
{
if(l>=r) return 0;
if(mp[l][r]!=-1) return mp[l][r];
cout<<"? "<<l<<" "<<r<<endl;
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=i;
while(l<=r)
{
int mid=(l+r)>>1;
if(ask(v[mid],i)) pos=mid,r=mid-1;
else l=mid+1;
}
for(int j=i-1;j>=pos;j--) v[j+1]=v[j];
v[pos]=i;
for(int j=1;j<=i;j++) p[v[i]]=i;
mp[i][i]=suf[i]=0;
for(int j=i-1;j>=1;j--) suf[j]=suf[j+1]^(p[i]<p[j]),mp[j][i]=mp[j][i-1]^suf[j];
}
cout<<"! ";
for(int i=1;i<=n;i++) p[v[i]]=i;
for(int i=1;i<=n;i++) cout<<p[i]<<" ";
cout.flush();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 19276kb
input:
3 0 0 0 1
output:
? 1 2 ? 1 3 ? 1 2 ? 2 3 ! 2 3 1
result:
ok OK, guesses=4
Test #2:
score: -100
Wrong Answer
time: 55ms
memory: 19140kb
input:
1993 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 1 1 1 0 0 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 1 1 1 0 1 1 0 1 1 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 1 1 1 1 0 0 1 1 0 1 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 1 0 1 1 1 0 1 0 0 0 1 0 0...
output:
? 1 2 ? 1 3 ? 1 2 ? 2 3 ? 2 4 ? 3 4 ? 2 5 ? 3 5 ? 1 5 ? 2 6 ? 3 6 ? 5 6 ? 1 6 ? 6 7 ? 5 7 ? 6 8 ? 7 8 ? 5 8 ? 1 9 ? 2 9 ? 8 9 ? 7 9 ? 1 10 ? 2 10 ? 3 10 ? 4 10 ? 1 11 ? 2 11 ? 10 11 ? 3 11 ? 4 11 ? 6 12 ? 7 12 ? 11 12 ? 3 12 ? 4 12 ? 6 13 ? 7 13 ? 11 13 ? 12 13 ? 3 13 ? 4 13 ? 5 13 ? 2 14 ? 3 14 ? 8...
result:
wrong answer Wa.