QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#539134 | #8939. Permutation | ucup-team1004# | WA | 54ms | 3876kb | C++14 | 777b | 2024-08-31 14:05:22 | 2024-08-31 14:05:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int query(int l,int r)
{
printf("? %d %d\n",l,r);
fflush(stdout);
scanf("%d",&l);
return l;
}
int solve(int l,int r,int p)
{
if(l==r) return l;
if(!p) p=query(l,r);
if(l==r-1) return l^r^p;
if(l==r-2)
{
if(p==l) return query(l+1,r)==r?l+1:r;
if(p==r) return query(l,r-1)==l?r-1:l;
return query(l,r-1)==r-1?l:r;
}
int k=(r-l)*(1-0.618),L=l+k,R=r-k;
if(l<=p&&p<=R)
{
int q=query(l,R);
return p==q?solve(l,R,q):solve(R+1,r,0);
}
else
{
int q=query(L+1,r);
return p==q?solve(L+1,r,q):solve(l,L,0);
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
int ans=solve(1,n,query(1,n));
printf("! %d\n",ans);
fflush(stdout);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3876kb
input:
3 5 3 3 2 6 6 3 1 4 3 2
output:
? 1 5 ? 1 4 ? 1 3 ! 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: 54ms
memory: 3752kb
input:
10000 10 2 2 2 2 3 10 10 10 7 5 10 5 5 1 6 10 4 4 4 4 4 10 10 6 3 3 2 10 3 3 3 3 3
output:
? 1 10 ? 1 7 ? 1 5 ? 1 4 ? 1 3 ! 4 ? 1 10 ? 5 10 ? 7 10 ? 5 6 ! 6 ? 1 10 ? 1 7 ? 1 5 ? 6 7 ! 7 ? 1 10 ? 1 7 ? 1 5 ? 1 4 ? 3 4 ! 3 ? 1 10 ? 5 10 ? 1 4 ? 1 3 ? 1 2 ! 1 ? 1 10 ? 1 7 ? 1 5 ? 1 4 ? 1 3 ? 1 2
result:
wrong answer Too many queries , n = 10 , now_q 6 (test case 6)