QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#607192 | #8939. Permutation | UESTC_NLNS# | WA | 80ms | 4112kb | C++14 | 922b | 2024-10-03 14:14:07 | 2024-10-03 14:14:07 |
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 pp,n;
int query(int l,int r)
{
if(mp.find(1ll*r*N+l)!=mp.end()) return mp[1ll*r*N+l];
int x;
printf("? %d %d\n",l,r);
pp+=r-l+1;
assert(pp<=3*n);
fflush(stdout);
scanf("%d",&x);
mp[1ll*r*N+l]=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,r);
if(x==y) solve(mid,r);
else solve(l,mid-1);
}
return;
}
int T;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);pp=0;
solve(1,n);
mp.clear();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4112kb
input:
3 5 3 2 5 6 6 3 1 4 3 3 2
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 2 4 ? 2 3 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: 0
Accepted
time: 80ms
memory: 3812kb
input:
10000 10 2 2 3 5 10 10 10 7 5 10 5 1 10 9 6 10 4 4 4 4 10 10 6 3 4 10 3 3 3 2 10 1 5 9 9 9 10 1 3 8 8 8 10 2 4 9 9 8 10 3 3 1 5 10 4 1 7 8 9 10 8 7 1 2 4 10 4 1 9 9 8 10 7 7 7 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