QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#607353 | #8939. Permutation | UESTC_xxx# | WA | 46ms | 3948kb | C++20 | 1.3kb | 2024-10-03 14:46:50 | 2024-10-03 14:46:57 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cmath>
#define lowbit(x) x&(-x)
#include<queue>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
int tt,n,pos,cnt1,cnt2;
void solve(int l,int r,int ls){
if(l==r){
printf("! %d\n",l);
fflush(stdout);
return;
}
if(r-l==1){
printf("? %d %d\n",l,r);
fflush(stdout);
scanf("%d",&pos);
printf("! %d\n",(pos==l)?r:l);
fflush(stdout);
cnt1++,cnt2+=r-l+1;
return;
}
if(!ls){
printf("? %d %d\n",l,r);
fflush(stdout);
scanf("%d",&pos);
cnt1++,cnt2+=r-l+1;
ls=pos;
}
int m1=(r-l)*2/3+l,m2=(r-l+1)/3+l;
if(ls<=m1){
printf("? %d %d\n",l,m1);
fflush(stdout);
scanf("%d",&pos);
cnt1++,cnt2+=m1-l+1;
if(m1-l==1){
printf("! %d\n",(pos==m1)?l:m1);
fflush(stdout);
return;
}
if(pos==ls){
solve(l,m1,ls);
}
else solve(m1+1,r,0);
}
else{
printf("? %d %d\n",m2,r);
fflush(stdout);
scanf("%d",&pos);
cnt1++,cnt2+=r-m2+1;
if(r-m2==1){
printf("! %d\n",(pos==m2)?r:m2);
fflush(stdout);
return;
}
if(pos==ls){
solve(m2,r,ls);
}
else solve(l,m2-1,0);
}
}
int main(){
scanf("%d",&tt);
while(tt--){
cnt1=cnt2=0;
scanf("%d",&n);
solve(1,n,0);
// double f=1.5*log2(n);
// printf("%lf\n%d %d\n",f,cnt1,cnt2);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3872kb
input:
3 5 3 2 5 6 6 3 1 4 3 2
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 1 3 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 46ms
memory: 3948kb
input:
10000 10 2 2 2 3 5 10 10 10 10 7 10 5 5 1 6 10 4 4 4 4 4
output:
? 1 10 ? 1 7 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 10 ? 4 10 ? 6 10 ? 7 10 ! 6 ? 1 10 ? 1 7 ? 1 5 ? 6 7 ! 7 ? 1 10 ? 1 7 ? 1 5 ? 2 5 ? 2 4 ? 3 4
result:
wrong answer Too many queries , n = 10 , now_q 6 (test case 4)