QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#649680 | #8939. Permutation | 11d10xy | WA | 1ms | 3824kb | C++14 | 536b | 2024-10-18 08:51:44 | 2024-10-18 08:51:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n;
inline int ask(int l,int r){
printf("? %d %d\n",l,r);fflush(stdout);
int x;scanf("%d",&x);return x;
}
int calc(int l,int r){
if(l==r)return l;
int mid=l+r>>1,x=calc(l,mid),y=calc(mid+1,r),res=ask(l,r);
if(res==x)return y;
if(res==y)return x;
if(l<=res&&res<=mid)return x;
else return y;
}
void solve(){
scanf("%d",&n);
printf("! %d\n",calc(1,n)),fflush(stdout);
}
int main(){
int T;for(scanf("%d",&T);T--;)solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3824kb
input:
3 5 1 2 5 3 6 1 3 4 5
output:
? 1 2 ? 1 3 ? 4 5 ? 1 5 ! 4 ? 1 2 ? 1 3 ? 4 5 ? 4 6 ? 1 6
result:
wrong answer Too many queries , n = 6 , now_q 5 (test case 2)