QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#608007 | #8939. Permutation | zzl | TL | 0ms | 0kb | C++17 | 713b | 2024-10-03 17:41:06 | 2024-10-03 17:41:06 |
Judging History
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