QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#109406 | #6303. Inversion | wfycsw | RE | 2ms | 19204kb | C++14 | 1.7kb | 2023-05-28 22:27:12 | 2023-05-28 22:27:15 |
Judging History
answer
#include<bits/stdc++.h>
#define RI register int
#define err puts("asd")
#define ll long long
#define ull unsigned long long
#define LL __int128
#define mk make_pair
#define fl fflush(stdout)
//#define int long long
using namespace std;
inline ll read(){
ll s=0;register char c=getchar();bool f=0;
while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}
while(c>='0'&&c<='9') s=(s<<3)+(s<<1)+c-48,c=getchar();
return f?-s:s;
}
const int N=2e3+5;
int n,a[N],f[N],to[N],cnt,b[N]={0,5,3,4,1,2};
int A[N][N];
inline void add(int x){while(x<=n) f[x]^=1,x+=x&-x;}
inline int ask(int x){RI ans=0;while(x) ans^=f[x],x^=x&-x;return ans;}
inline int get1(int l,int r){
RI tmp=0;
for(RI i=r;i>=l;--i){
tmp^=ask(b[i]);
add(b[i]);
}
for(RI i=l;i<=r;++i) add(b[i]);
return tmp;
}
inline int Q(int x,int y){
if(x>=y) return 0;
if(A[x][y]!=-1) return A[x][y];
if(++cnt>40000) exit(1);
cout<<"? "<<x<<' '<<y<<endl;fl;
RI z=read();
return A[x][y]=z;
}
inline int get(int l,int r){
RI tmp=0;
for(RI i=r;i>=l;--i){
tmp^=ask(a[i]);
add(a[i]);
}
for(RI i=l;i<=r;++i) add(a[i]);
return tmp;
}
signed main(){
//freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
n=read();
memset(A,-1,sizeof A);
RI x,y,z,l,r,mid,ans;
for(RI i=1;i<=n;++i){
l=1;r=i-1;ans=0;
while(l<=r){
mid=l+r>>1;
if(Q(to[mid],i)^Q(to[mid]+1,i)^Q(to[mid]+1,i-1)^Q(to[mid],i-1)==0) l=mid+1,ans=mid;
else r=mid-1;
}
//cout<<"debug "<<ans<<endl;
for(RI j=1;j<i;++j)
if(a[j]>ans) ++a[j];
a[i]=ans+1;
for(RI j=1;j<=i;++j) to[a[j]]=j;
}
cout<<"! ";
for(RI i=1;i<=n;++i) cout<<a[i]<<' ';fl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 19204kb
input:
3 0 0 1
output:
? 1 2 ? 1 3 ? 2 3 ! 2 3 1
result:
ok OK, guesses=3
Test #2:
score: -100
Runtime Error
input:
1993 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 0 1 1 1 1 1 1 0 1 1 1 1 1 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 1 0 0 1 1 0 0 1 1 1 1 1 0 1 0 0 0 1 0 1 1 1 0 1 0 0 1 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 0 1 1 1 1 0 1 0 0 0 1 1 0 1 1 1 1 1 1 0 0 0 1 0 0 0 0 1 0 1 0 1 1 1 0 0 0 0 1 0 0 1...
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4 ? 3 4 ? 2 5 ? 3 5 ? 1 5 ? 1 4 ? 2 6 ? 3 6 ? 5 6 ? 1 6 ? 1 7 ? 2 7 ? 5 7 ? 6 7 ? 1 8 ? 2 8 ? 3 8 ? 4 8 ? 4 7 ? 3 7 ? 1 9 ? 2 9 ? 8 9 ? 3 9 ? 9 10 ? 5 10 ? 6 10 ? 6 9 ? 5 9 ? 7 10 ? 8 10 ? 7 9 ? 1 11 ? 2 11 ? 2 10 ? 1 10 ? 8 11 ? 9 11 ? 10 11 ? 11 12 ? 8 12 ? 9 12 ? 10 12 ? 2 1...