QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#606623 | #8939. Permutation | liguo# | WA | 0ms | 3864kb | C++20 | 709b | 2024-10-03 11:03:21 | 2024-10-03 11:03:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n;scanf("%d",&n);
int l=1,r=n,sl;
printf("? %d %d\n",l,r);
fflush(stdout);
scanf("%d",&sl);
while(l<r){
// printf("**");
if(l+1==r){
printf("! %d\n",l+r-sl);
fflush(stdout);
return;
}
int fl=0;
int mid=l+(r-l)/2;
if(l<=sl&&sl<=mid){
printf("? %d %d\n",l,mid);
fflush(stdout);
int res;scanf("%d",&res);
if(res==sl)
r=mid;
else
l=mid,sl=res;
}
else{
printf("? %d %d\n",mid,r);
fflush(stdout);
int res;scanf("%d",&res);
if(res==sl)
l=mid;
else
r=mid,sl=res;
}
}
}
int main(){
int t;scanf("%d",&t);
while(t--){
solve();
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3864kb
input:
3 5 3 2 5
output:
? 1 5 ? 1 3 ? 4 5 ! 2
result:
wrong answer Wrong prediction (test case 1)