QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#649696 | #8939. Permutation | 11d10xy | WA | 57ms | 3920kb | C++14 | 751b | 2024-10-18 09:00:50 | 2024-10-18 09:00:50 |
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,int res){
if(l==r)return l;
int mid=l+r>>1;
if(!res)res=ask(l,r);
if(res<=mid){
if(l==mid)return calc(mid+1,r,0);
int x=ask(l,mid);
if(x==res)return calc(l,mid,res);
else return calc(mid+1,r,0);
}else{
if(mid+1==r)return calc(l,mid,0);
int x=ask(mid+1,r);
if(x==res)return calc(mid+1,r,res);
else return calc(l,mid,0);
}
}
void solve(){
scanf("%d",&n);
printf("! %d\n",calc(1,n,0)),fflush(stdout);
}
int main(){
int T;for(scanf("%d",&T);T--;)solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3836kb
input:
3 5 3 2 5 6 6 5 3 1 4 3 3
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 4 6 ? 1 3 ? 1 2 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 57ms
memory: 3920kb
input:
10000 10 2 2 3 5 10 10 10 9 7 7 10 5 1 10 9 6
output:
? 1 10 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 10 ? 6 10 ? 9 10 ? 6 8 ? 6 7 ! 6 ? 1 10 ? 1 5 ? 6 10 ? 9 10 ? 6 8 ? 6 7
result:
wrong answer Too many queries , n = 10 , now_q 6 (test case 3)