QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#661359#6303. Inversionlibantian#WA 34ms3776kbC++232.4kb2024-10-20 15:55:032024-10-20 15:55:04

Judging History

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

  • [2024-10-20 15:55:04]
  • 评测
  • 测评结果:WA
  • 用时:34ms
  • 内存:3776kb
  • [2024-10-20 15:55:03]
  • 提交

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;

int query(int l,int r){
    cout<<"? "<<l<<" "<<r<<endl;
    int x=0;
    cin>>x;
    return x;
    //return x&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;
    // init(r-l+2);
    // for(int i=mid+1;i<=r;i++){
    //     stt[i]=get(i-mid);
    //     add(i-mid,r-l+2);
    // }
    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;
        //cout<<st<<" "<<ed<<" "<<now<<endl;
        if(ed==n+1){
            if(query(st,now)==query(mid+1,now)){
                res.push_back(st);
                ql.pop();
            }else{
                res.push_back(now);
                qr.pop();
            }
        }else{
            if(query(st,now)==query(ed,now)){
                res.push_back(st);
                ql.pop();
            }else{
                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);
    cout<<"! ";
    for(int i=1;i<=n;i++){
        cout<<n-a[i]+1<<" ";
    }
    cout<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    // cout << setiosflags(ios::fixed) << setprecision(15);
    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: 3656kb

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: 34ms
memory: 3776kb

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
1
0
0
0
0
0
0
0
1
1
0
1
0
0
0
0
0
0
1
1
1
1
1
1
0
0
0
1
0
1
1
1
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
1
0
1
1
0
0
0
0
0
0
0
0
1
1
1
1
0
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
0
1
1
1
1
1
1
1
1
1
0
0
0
0
1
0
1
1
1
1
1...

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
? 13 14
? 14 14
? 15 16
? 16 16
? 14 15
? 15 15
? 13 15
? ...

result:

wrong answer Wa.