QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#538363 | #8939. Permutation | ucup-team3555# | WA | 0ms | 3540kb | C++20 | 816b | 2024-08-31 10:54:12 | 2024-08-31 10:54:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+3;
ll n;
int Ask(int l,int r)
{
cout<<"? "<<l<<" "<<r<<endl;
int x;cin>>x;
return x;
}
int Sol(int l,int r)
{
if(l==r)return l;
int p=Ask(l,r),op=0;
if(l+1==r)return p==l?l+1:l;
if(p-l<=r-p)op=(p==l||Ask(l,p)!=p)?1:0;
else op=(p==r||Ask(p,r)==p)?0:1;
if(!op)
{
int kl=l,kr=p-1;
while(kl<kr)
{
int mi=(kl+kr)/2+1;
if(Ask(mi,p)==p)kl=mi;
else return Sol(l,mi-1);
}
return p-1;
}
else
{
int kl=p+1,kr=r;
while(kl<kr)
{
int mi=(kl+kr)/2;
if(Ask(p,mi)==p)kr=mi;
else return Sol(mi+1,r);
}
return p+1;
}
}
void Solve()
{
cin>>n;
int x=Sol(1,n);
cout<<"! "<<x<<endl;
}
int main()
{
int T;cin>>T;
while(T--)Solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3540kb
input:
3 5 3 2 3 6 6 5 3 3 4 3 3 2
output:
? 1 5 ? 1 3 ? 3 4 ! 4 ? 1 6 ? 4 6 ? 1 3 ? 2 3 ! 2 ? 1 4 ? 3 4 ? 2 3 ! 1
result:
wrong answer Wrong prediction (test case 3)