QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#607208 | #8939. Permutation | UESTC_NLNS# | WA | 51ms | 4080kb | C++14 | 915b | 2024-10-03 14:17:32 | 2024-10-03 14:17:33 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
unordered_map<ll,int> mp;
const int N=1e6+5;
void answer(int x)
{
printf("! %d\n",x);
fflush(stdout);
return;
}
int query(int l,int r)
{
ll id=1ll*l*N+r;
if(mp.find(id)!=mp.end()) return mp[id];
int x;
printf("? %d %d\n",l,r);
fflush(stdout);
scanf("%d",&x);
mp[id]=x;
return x;
}
void solve(int l,int r)
{
if(l==r)
{
answer(l);
return;
}
int mid=(l+r)>>1,x=query(l,r),y;
if(l+1==r)
{
if(x==l) answer(r);
else answer(l);
return;
}
if(x<=mid)
{
y=query(l,mid);
if(x==y) solve(l,mid);
else solve(mid+1,r);
}
else
{
if(mid+1==r) {solve(l,r-1);return;}
y=query(mid+1,r);
if(x==y) solve(mid+1,r);
else solve(l,mid);
}
return;
}
int T,n;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
solve(1,n);
mp.clear();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4080kb
input:
3 5 3 2 5 6 6 5 3 1 4 3 3
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 4 6 ? 1 3 ? 1 2 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 51ms
memory: 4080kb
input:
10000 10 2 2 3 5 10 10 10 9 7 7 10 5 1 10 9 6
output:
? 1 10 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 10 ? 6 10 ? 9 10 ? 6 8 ? 6 7 ! 6 ? 1 10 ? 1 5 ? 6 10 ? 9 10 ? 6 8 ? 6 7
result:
wrong answer Too many queries , n = 10 , now_q 6 (test case 3)