QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#607196 | #8939. Permutation | UESTC_NLNS# | WA | 1ms | 3860kb | C++14 | 876b | 2024-10-03 14:15:26 | 2024-10-03 14:15:26 |
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
{
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;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3860kb
input:
3 5 3 2 5 6 6 5 3
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 4 6 ? 1 3 ? 3 3
result:
wrong answer Integer 3 violates the range [4, 6] (test case 2)