QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#662067#6303. InversionlibantianWA 57ms4100kbC++233.4kb2024-10-20 20:29:502024-10-20 20:30:18

Judging History

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

  • [2024-10-20 20:30:18]
  • 评测
  • 测评结果:WA
  • 用时:57ms
  • 内存:4100kb
  • [2024-10-20 20:29:50]
  • 提交

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=20010;
int a[N],tr[N];
int n;
map<pii,int>mp;
int query(int l,int r){
    cout<<"? "<<l<<" "<<r<<endl;
    cout.flush(); 
    int x;
    cin>>x;
    return x;
    //return x&1;
}
int lowbit(int x){
    return x&-x;
}
void init(int len){
    for(int i=1;i<=len;i++)tr[i]=0;
}
void add(int u,int len){
    for(int i=u;i<=len;i+=lowbit(i))tr[i]++;
}
int get(int u){
    int res=0;
    for(int i=u;i;i-=lowbit(i))res+=tr[i];
    return res;
}
int get(int l,int r,int L,int R){
    int len=R-L+1;
    init(len);
    int res=0;
    for(int i=l;i<=r;i++){
        res+=get(len-a[i]+1);
        add(a[i],len);
    }
    //cout<<"->"<<l<<" "<<r<<" "<<res<<endl;
    return res&1;

}
void build(int l,int r){
    // cout<<l<<" "<<r<<endl;
    if(l==r){
        a[l]=1;
        return ;
    }
    int mid=(l+r)/2;
    build(l,mid);
    build(mid+1,r);
    vector<int> stk,res;
    stk.push_back(n+1);
    map<int,int>pos,stt;
    for(int i=mid;i>=l;i--){
        while(a[i]<a[stk.back()])stk.pop_back();
        pos[i]=stk.back();
        stk.push_back(i);
    }
    //cout<<pos[1]<<" "<<pos[2]<<endl;
    priority_queue<pii>ql,qr;
    for(int i=l;i<=mid;i++){
        ql.push({a[i],i});
    }
    for(int i=mid+1;i<=r;i++){
        qr.push({a[i],i});
    }

    while(qr.size()){
        if(ql.size()==0){
            res.push_back(qr.top().se);
            qr.pop();
            continue;
        }
        int st=ql.top().se;
        int ed=pos[st];
        int now=qr.top().se;
        
        if(ed==n+1){
            ed=mid;
            
            int t;
            if(mp.find({st,ed})==mp.end()){
                mp[{st,ed}]=get(st,ed,l,mid);
            }
            t=mp[{st,ed}];
            if((query(st,now)^t)==query(mid+1,now)){
                res.push_back(st);
                ql.pop();
            }else{
                res.push_back(now);
                qr.pop();
            }
        }else{
            int t;
            if(mp.find({st,ed-1})==mp.end()){
                mp[{st,ed-1}]=get(st,ed-1,l,mid);
            }
            //cout<<st<<" "<<ed-1<<" "<<now<<endl;
            t=mp[{st,ed-1}];
            if((query(st,now)^t)==query(ed,now)){
                res.push_back(st);
                ql.pop();
            }else{
                //cout<<66<<endl;
                res.push_back(now);
                qr.pop();
            }
        }
    }
    while(ql.size()){
        res.push_back(ql.top().se);
        ql.pop();
    }
    for(int i=0;i<res.size();i++){
        a[res[i]]=res.size()-i;
    }
     
}
void solve(){
    cin>>n;
    a[n+1]=-INF;
     build(1,n);
    // build(1,1);
    // build(2,2);
    // build(1,2);
    // build(3,3);
    // cout<<"======="<<endl;
    // build(1,3);
    // for(int i=1;i<=n;i++){
    //     cout<<a[i]<<" ";
    // }
    // cout<<endl;
    cout<<"! ";
    for(int i=1;i<n;i++){
        cout<<n-a[i]+1<<" ";
    }
    cout<<n-a[n]+1;
   
}
signed main(){
    fflush(stdout);
    cout.flush(); 
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    
    int T;
    T=1;
    // cin>>T;
    while(T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
0
0
0
1

output:

? 1 2
? 2 2
? 1 3
? 2 3
! 2 3 1

result:

ok OK, guesses=4

Test #2:

score: -100
Wrong Answer
time: 57ms
memory: 4100kb

input:

1993
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
1
0
1
0
1
0
1
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
1
1
1
0
1
0
0
0
0
0
0
0
1
1
1
1
1
1
0
0
0
1
0
1
1
1
1
1
1
0
0
1
1
0
0
0
0
0
0
0
0
1
0
1
1
0
0
0
0
0
0
0
1
0
0
1
0
1
1
1
1
0
1
1
1
0
0
0
0
0
0
1
0
0
0
0
1
0
1
0
1
1
0
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0...

output:

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

result:

wrong answer Wa.