QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#858130#8939. PermutationLe0ChanWA 0ms3584kbC++141.1kb2025-01-16 14:23:222025-01-16 14:23:23

Judging History

This is the latest submission verdict.

  • [2025-01-16 14:23:23]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3584kb
  • [2025-01-16 14:23:22]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
namespace Le0{
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define db double
#define _int __int128
#define vi vector<int>
#define tii tuple<int,int,int>
const int inf=0x3f3f3f3f;
const ll lnf=1e18;
int n,as;
int qry(int l,int r){
    if(l==r) return l;
    cout<<"? "<<l<<' '<<r<<endl;
    cin>>l;return l;
}
void sol(int l,int r,int p){
    if(l+1==r){
        if(p==l) as=r;
        else as=l;
        return;
    }
    if(l==r){as=l;return;}
    int len=(r-l+1)/3,mid,op;
    if(p<=l+len*2-1) mid=l+len*2-1,op=0;
    else mid=r-len*2,op=1;
    int p2=(op?qry(mid+1,r):qry(l,mid));
    if(p2==p) (op?sol(mid+1,r,p):sol(l,mid,qry(l,mid)));
    else (op?sol(l,mid,qry(l,mid)):sol(mid+1,r,p));
}
void sv(){
    cin>>n;
    sol(1,n,qry(1,n));
    cout<<"! "<<as<<endl;
}
int main(){
    int _T;cin>>_T;
    while(_T--){
        sv();
    }
    return 0;
}
}
int main(){
    ios::sync_with_stdio(0),cin.tie(0);
    return Le0::main();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3584kb

input:

3
5
3
5
2
1

output:

? 1 5
? 4 5
? 1 3
? 1 2
! 3

result:

wrong answer Wrong prediction (test case 1)