QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#541073#8939. Permutationucup-team4508#TL 0ms0kbC++23757b2024-08-31 18:35:292024-08-31 18:35:30

Judging History

This is the latest submission verdict.

  • [2024-08-31 18:35:30]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 0kb
  • [2024-08-31 18:35:29]
  • Submitted

answer

#include<iostream>
#include<algorithm>
#include<map>
std::map<std::pair<int,int>,int>c;
int query(int l,int r){
    if(l==r)return l;
    if(c[{l,r}]!=0)return c[{l,r}];
    std::cout<<"? "<<l<<" "<<r<<std::endl;
    int res;
    std::cin>>res;
    return c[{l,r}]=res;
}
int solve(int l,int r){
    if(l==r)return l;
    int t=query(l,r);
    if(r-l==1)return r==t?l:r;
    int x=query(t,r);
    if(x==t)return solve(t+1,r);
    else return solve(l,t-1);
}
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t;
    std::cin>>t;
    while(t--){
        c.clear();
        int n;
        std::cin>>n;
        int res=solve(1,n);
        std::cout<<"! "<<res<<std::endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3
5
3
3
5
6
6

output:

? 1 5
? 3 5
? 4 5
! 4
? 1 6
? 7 6

result: