QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#138320#6303. InversionyzhangWA 59ms19348kbC++141.7kb2023-08-11 14:22:222023-08-11 14:22:24

Judging History

你现在查看的是最新测评结果

  • [2023-08-11 14:22:24]
  • 评测
  • 测评结果:WA
  • 用时:59ms
  • 内存:19348kb
  • [2023-08-11 14:22:22]
  • 提交

answer

//μ's forever
#include <bits/stdc++.h>
#define N 2005
//#define getchar nc
using namespace std;
inline char nc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read()
{
    register int x=0,f=1;register char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return x*f;
}
inline void write(register int x)
{
    if(!x)putchar('0');if(x<0)x=-x,putchar('-');
    static int sta[20];register int tot=0;
    while(x)sta[tot++]=x%10,x/=10;
    while(tot)putchar(sta[--tot]+48);
}
int n;
int p[N],ip[N],f[N][N];
int qry(int l,int r){
    if(l>=r) return 0;
    if(f[l][r]!=-1) return f[l][r];
    printf("? %d %d\n",l,r);
    fflush(stdout);
    int x=read();
    f[l][r]=x;
    return x;
}
int chk(int l,int r){
    return ((qry(l,r)-qry(l,r-1)-qry(l+1,r)+qry(l+1,r-1))%2+2)%2;
}
void solve(int pos){
    int l=1,r=pos-1,res=pos;
    while(l<=r){
        int mid=l+r>>1;
        if(chk(ip[mid],pos)){
            res=mid,r=mid-1;
        }else{
            l=mid+1;
        }
    }
    p[pos]=res;
    for(int i=1;i<pos;++i) if(p[i]>=res) ++p[i];
    for(int i=1;i<=pos;++i) ip[p[i]]=i;
    f[pos][pos]=0;
    for(int i=pos-1;i>=1;--i){
        f[i][pos]=f[i+1][pos]+f[i][pos-1]-f[i+1][pos-1]+(p[i]>p[pos]);
    }
}
int main()
{
    memset(f,-1,sizeof(f));
    n=read();
    for(int i=1;i<=n;++i) f[i+1][i]=0;
    p[1]=1,ip[1]=1;
    for(int i=2;i<=n;++i){
        solve(i);
    }
    putchar('!');
    for(int i=1;i<=n;++i) printf(" %d",p[i]);
    fflush(stdout);
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 19300kb

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: 0
Accepted
time: 59ms
memory: 19292kb

input:

1993
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
1
0
1
0
0
0
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
1
1
1
1
0
1
1
1
1
1
0
0
0
1
0
1
0
1
0
0
0
0
1
1
0
0
1
0
0
1
1
1
1
1
0
1
1
1
1
1
1
0
0
0
0
0
0
1
0
1
1
1
0
0
1
0
1
1
0
1
1
0
1
1
0
0
1
0
0
0
1
1
0
1
1
0
0
0
1
0
1
0
0
1
1
0
0
1
0
0
1
1
1
1
1
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
? 1 7
? 2 7
? 5 7
? 6 7
? 1 8
? 2 8
? 3 8
? 4 8
? 1 9
? 2 9
? 8 9
? 3 9
? 9 10
? 5 10
? 6 10
? 7 10
? 8 10
? 1 11
? 2 11
? 8 11
? 9 11
? 10 11
? 11 12
? 8 12
? 9 12
? 10 12
? 2 12
? 3 12
? 11 13
? 12 13
? 3 13
? 4 13
? 5 1...

result:

ok OK, guesses=37851

Test #3:

score: -100
Wrong Answer
time: 55ms
memory: 19348kb

input:

1887
1
0
0
0
0
0
1
1
1
1
0
0
0
1
1
1
0
0
1
0
0
0
0
1
1
0
1
1
1
0
0
1
0
0
0
0
1
0
1
0
0
1
0
1
1
1
1
1
1
1
1
0
1
1
1
1
1
0
1
1
1
1
1
0
0
0
0
1
0
1
1
0
1
1
1
0
0
0
0
1
1
0
0
1
1
0
0
1
1
1
1
0
0
0
1
0
1
0
1
1
0
0
0
1
0
1
0
1
1
0
0
1
0
1
0
0
1
0
0
1
0
1
0
0
0
1
1
1
0
1
1
1
1
0
0
0
1
0
0
1
1
0
1
1
1
0
0
0...

output:

? 1 2
? 2 3
? 1 3
? 1 4
? 2 4
? 3 4
? 1 5
? 2 5
? 3 5
? 4 5
? 3 6
? 4 6
? 5 6
? 3 7
? 4 7
? 6 7
? 5 7
? 7 8
? 6 8
? 4 8
? 5 8
? 7 9
? 8 9
? 6 9
? 4 9
? 5 9
? 5 10
? 6 10
? 1 10
? 2 10
? 3 10
? 7 11
? 8 11
? 9 11
? 5 11
? 6 11
? 5 12
? 6 12
? 1 12
? 2 12
? 3 12
? 4 12
? 7 12
? 8 12
? 12 13
? 1 13
? 2...

result:

wrong answer Wa.