QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#662750 | #6303. Inversion | libantian | WA | 76ms | 35248kb | C++23 | 1.6kb | 2024-10-21 09:54:52 | 2024-10-21 09:54:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define fi first
#define se second
#define all(_a) _a.begin(), _a.end()
const int N=2010;
int a[N],pos[N];
int vis[N][N];
int query(int l,int r){
if (l>=r) return 0;
if (~vis[l][r]) return vis[l][r];
cout<<"? "<<l<<' '<<r<<endl,fflush(stdout);
return cin>>vis[l][r],vis[l][r];
}
int ask(int l,int r){
//cout<<l<<" "<<r<<endl;
if(l+1==r)return query(l,r);
return query(l+1,r-1)^query(l,r-1)^query(l+1,r)^query(l,r);
}
signed main(){
int n;
cin>>n;
memset(vis,-1,sizeof vis);
pos[1]=1;
a[1]=1;
for(int i=1;i<=n;i++)vis[1][1]=0;
for(int i=2;i<=n;i++){
int t=i-1,l=1,r=t,res=i;
// if(ask(pos[i-1],i)==0){
// pos[i]=i;
// }else{
// int l=1,r=i-1;
// while(l<r){
// int mid=l+r>>1;
// if(ask(pos[mid],i))r=mid;
// else l=mid+1;
// }
// for(int j=i;j>l;j--)pos[j]=pos[j-1];
// pos[l]=i;
// }
while(l<=r){
int mid=l+r>>1;
if(ask(pos[mid],i))res=mid,r=mid-1;
else l=mid+1;
}
for(int j=t;j>=res;j--)pos[j+1]=pos[j];
pos[res]=i;
for(int j=1;j<=i;j++)a[pos[j]]=j;
int T=0;
for(int j=i-1;j;j--){
if(a[j]>a[i])T^=1;
vis[j][i]=vis[j][i-1]^T;
}
}
cout<<"! ";
for(int i=1;i<=n;i++)cout<<a[i]<<' ';
return fflush(stdout),0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 35164kb
input:
3 0 1 0
output:
? 1 2 ? 2 3 ? 1 3 ! 2 3 1
result:
ok OK, guesses=3
Test #2:
score: -100
Wrong Answer
time: 76ms
memory: 35248kb
input:
1993 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0 1 0 1 1 1 0 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 1 1 0 0 1 1 1 1 1 1 0 0 0 0 1 1 0 1 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0 0 1 0 1 0 1 1 1 1 0 0 0 1 0 0 0 0 1 0 0 1 0 1 0 0 0 0 1 0 1 1 1 0 0...
output:
? 1 2 ? 2 3 ? 1 3 ? 2 3 ? 3 4 ? 2 4 ? 3 4 ? 3 5 ? 2 5 ? 1 5 ? 3 6 ? 2 6 ? 5 6 ? 1 6 ? 2 7 ? 1 7 ? 5 6 ? 6 7 ? 5 7 ? 2 8 ? 1 8 ? 4 8 ? 3 8 ? 2 9 ? 1 9 ? 8 9 ? 3 9 ? 9 10 ? 6 9 ? 6 10 ? 5 10 ? 8 10 ? 7 10 ? 2 11 ? 1 11 ? 9 11 ? 8 11 ? 10 11 ? 11 12 ? 9 11 ? 9 12 ? 8 12 ? 10 11 ? 10 12 ? 3 12 ? 2 12 ? ...
result:
wrong answer Wa.