QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#109589 | #6303. Inversion | wfycsw | WA | 4ms | 19048kb | C++14 | 1.7kb | 2023-05-29 20:29:56 | 2023-05-29 20:30:01 |
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,1,5,4,2,3};
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=get1(x,y);
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)^get(to[mid]+1,i-1)^get(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;
}
详细
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 19048kb
input:
3 0 0 1
output:
? 1 2 ? 1 3 ? 2 3 ! 1 2 3
result:
wrong answer Wa.