QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#554924 | #8939. Permutation | donghanwen1225 | WA | 10ms | 3948kb | C++14 | 938b | 2024-09-09 18:03:21 | 2024-09-09 18:03:21 |
Judging History
answer
#include<iostream>
#include<cstdio>
using namespace std;
int t,n;
int qry(int l,int r)
{
printf("? %d %d\n",l,r);fflush(stdout);
int x;scanf("%d",&x);return x;
}
void ans(int x){printf("! %d\n",x);fflush(stdout);}
void sol(int l,int r,int k)
{
if(l==r){ans(l);return;}
if(r-l==1)
{
if(k) ans(l+r-k);
else ans(l+r-qry(l,r));
return;
}
if(!k) k=qry(l,r);
if(k==l)
{
int mid=(l+r)/2;
int res=qry(l,mid);
if(res==l) sol(l,mid,l);
else sol(mid+1,r,0);
}
else if(k==r)
{
int mid=(l+r)/2;
int res=qry(mid,r);
if(res==r) sol(mid,r,r);
else sol(l,mid-1,0);
}
else
{
int mid=(l+r)/2,res=0;
if(k<=mid)
{
res=qry(l,k);
if(res==k) sol(l,k,k);
else sol(k,r,k);
}
else
{
res=qry(k,r);
if(res==k) sol(k,r,k);
else sol(l,k,k);
}
}
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
sol(1,n,0);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3756kb
input:
3 5 3 2 3 6 6 3 1 4 3 3
output:
? 1 5 ? 1 3 ? 3 4 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 10ms
memory: 3948kb
input:
10000 10 2 1 2 2 3 10 10 10 7 5 10 5 1 5 6 10 4 4 4 4 10 10 6 3 4 2 10 3 3 2 10 1 5 9 10 9
output:
? 1 10 ? 1 2 ? 2 6 ? 2 4 ? 2 3 ! 4 ? 1 10 ? 5 10 ? 7 10 ? 5 6 ! 6 ? 1 10 ? 1 5 ? 5 7 ? 5 6 ! 7 ? 1 10 ? 1 4 ? 2 4 ? 3 4 ! 3 ? 1 10 ? 5 10 ? 1 4 ? 3 4 ? 2 3 ! 1 ? 1 10 ? 1 3 ? 2 3 ! 1 ? 1 10 ? 1 5 ? 6 10 ? 9 10 ? 7 9 ? 8 9
result:
wrong answer Too many queries , n = 10 , now_q 6 (test case 7)