QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#608007#8939. PermutationzzlTL 0ms0kbC++17713b2024-10-03 17:41:062024-10-03 17:41:06

Judging History

This is the latest submission verdict.

  • [2024-10-03 17:41:06]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 0kb
  • [2024-10-03 17:41:06]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,l,r;
int qu(int l,int r) {
    cout<<'?'<<' '<<l<<' '<<r<<endl;
    cout.flush();
    int tem;
    cin>>tem;
    return tem;
}
int work(int l,int r,int s) {
    if(l==r)return l;
    if(s==0)s=qu(l,r);
    if(l==r-1)return s==l?r:l;
    int up=0.4*(r-l);
    if(r-s>=s-l) {
        if(qu(l,r-up)==s)return work(l,r-up,s);
        else return work(r-up+1,r,0);
    }
    else {
        if(qu(l+up,r)==s)return work(l+up,r,s);
        else return work(l,l+up-1,0);
    }
}
signed main() {
    int t;
    cin>>t;
    while(t--) {
        cin>>n;
        n=work(1,n,0);
        cout<<'!'<<' '<<n<<endl;
    }
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

3
5
3
3
3
3

output:

? 1 5
? 1 4
? 2 4
? 2 4
? 2 4

result: