QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#661436#6303. Inversionlibantian#WA 61ms3788kbC++232.2kb2024-10-20 16:13:262024-10-20 16:13:27

Judging History

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

  • [2024-10-20 16:13:27]
  • 评测
  • 测评结果:WA
  • 用时:61ms
  • 内存:3788kb
  • [2024-10-20 16:13:26]
  • 提交

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 cnt=0;
int query(int l,int r){
    cout<<"? "<<l<<" "<<r<<endl;
    cout.flush(); 
    int x;
    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);
    }
   
    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){
            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<<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;
}

详细

Test #1:

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

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: 61ms
memory: 3788kb

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.