QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#883134 | #9734. Identify Chord | chrhaa | WA | 10ms | 1664kb | C++14 | 896b | 2025-02-05 14:52:26 | 2025-02-05 14:52:31 |
Judging History
answer
#include<stdio.h>
using namespace std;
#define ll long long
ll T,n,m,f;
inline ll ask(ll x,ll y){
if(f) x=n-x%n,y=n-y%n;
ll z;
printf("? %lld %lld\n",(x-1)%n+1,(y-1)%n+1);
fflush(stdout);
scanf("%lld",&z);
return z;
}
inline ll found(ll x,ll y){
if(f) x=n-x%n,y=n-y%n;
ll z;
printf("! %lld %lld\n",(x-1)%n+1,(y-1)%n+1);
fflush(stdout);
scanf("%lld",&z);
return z;
}
signed main(){
ll x,y,z,l,r,mid;
scanf("%lld",&T);
while(T--){
scanf("%lld",&n);
m=n/2;
x=1;
y=m+1;
f=0;
while((z=ask(x,y))==m) if(n&1){
if(x+m<y) x++;
else y++;
}else x++,y++;
if(ask(x,y+1)<m){
f=1;
x=n-x;
y=n+n-y;
}
l=x,r=y;
while(l<r){
mid=l+r>>1;
if(ask(x,mid)==z-y+mid) r=mid;
else l=mid+1;
}
z-=y-l+1;
if(ask(n+x-z,l)==1) found(n+x-z,l);
else found(x+z,l);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 1664kb
input:
2 6 2 2 1 2 1 1 4 1 1 1 1 1
output:
? 1 4 ? 1 5 ? 1 6 ? 1 5 ? 2 4 ! 2 4 ? 1 3 ? 1 4 ? 1 4 ? 1 3 ! 1 3
result:
ok ok (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 10ms
memory: 1664kb
input:
1000 15 5 6 4 6 6 1 1 19 5 4 5 3 4 1 1 17 5 4 4 3 4 1 1 15 6 7 2 1 1 1 1 14 5 6 3 5 6 3 -1
output:
? 1 8 ? 1 9 ? 1 12 ? 1 10 ? 1 9 ? 5 8 ! 5 8 ? 1 10 ? 1 11 ? 1 15 ? 1 12 ? 1 13 ? 3 12 ! 3 12 ? 1 9 ? 1 10 ? 1 14 ? 1 11 ? 1 12 ? 3 11 ! 3 11 ? 1 8 ? 1 9 ? 1 4 ? 1 2 ? 1 3 ? 1 3 ! 1 3 ? 1 8 ? 1 9 ? 1 12 ? 1 10 ? 1 9 ? 5 8 ! 11 8
result:
wrong answer Wrong answer n=14, actual=2-5, guessed=11-8 (test case 5)