QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#152312 | #6303. Inversion | chen_zexing | WA | 93ms | 3752kb | C++17 | 1.2kb | 2023-08-28 00:00:28 | 2023-08-28 00:00:30 |
Judging History
answer
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
int a[2005],p[2005],tot,suf[2005];
int query(int l,int r){
if(l==r) return 0;
tot++;
assert(tot<=40000);
printf("? %d %d\n",l,r);
fflush(stdout);
int t;
scanf("%d",&t);
return t;
}
int tree[2005];
void add(int x,int v,int n){
while(x<=n) tree[x]+=v,x+=x&-x;
}
int query(int x){
int ans=0;
while(x) ans+=tree[x],x-=x&-x;
return ans;
}
int main() {
int T = 1, kase = 0;
//cin >> T;
while (T--) {
int n;
cin>>n;
a[1]=p[1]=1;
for(int i=2;i<=n;i++){
int l=0,r=i-1;
while(l<r){
int mid=(l+r+1)/2;
if(query(p[mid],i)!=query(p[mid]+1,i)^suf[p[mid]]) r=mid-1;
else l=mid;
}
for(int j=l+1;j<i;j++) a[p[j]]++;
a[i]=l+1;
for(int j=1;j<=i;j++) p[a[j]]=j;
for(int j=1;j<=i;j++) tree[j]=0;
for(int j=i;j;j--) suf[j]=query(a[j]),add(a[j],1,i);
}
printf("!");
for(int i=1;i<=n;i++) printf(" %d",a[i]);
puts("");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3744kb
input:
3 0 0 1
output:
? 1 2 ? 1 3 ? 2 3 ! 2 3 1
result:
ok OK, guesses=3
Test #2:
score: -100
Wrong Answer
time: 93ms
memory: 3752kb
input:
1993 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 1 1 0 1 1 0 0 1 1 1 1 1 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 0 0 0 0 1 0 0 1 0 1 1 1 0 1 1 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 1 1 1 1 0 1 1 0 0 1 1 0 0 1 0 1 0 1 1 1 1 0 1 1 0 0 0 1 0 1 1 0 1 0 0 1 1 0 0 1 0 0 0 0 1 0 0 1 0 0 0 1 1 0 0...
output:
? 1 2 ? 1 3 ? 2 3 ? 2 3 ? 2 4 ? 3 4 ? 3 4 ? 2 5 ? 3 5 ? 1 5 ? 2 5 ? 2 6 ? 3 6 ? 5 6 ? 1 6 ? 2 6 ? 1 7 ? 2 7 ? 5 7 ? 6 7 ? 1 8 ? 2 8 ? 5 8 ? 6 8 ? 6 8 ? 7 8 ? 8 9 ? 5 9 ? 6 9 ? 6 9 ? 7 9 ? 8 10 ? 9 10 ? 5 10 ? 6 10 ? 7 10 ? 8 10 ? 9 11 ? 10 11 ? 10 11 ? 5 11 ? 6 11 ? 9 12 ? 10 12 ? 11 12 ? 5 12 ? 6 1...
result:
wrong answer Wa.