QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#607491 | #8939. Permutation | UESTC_NLNS# | WA | 140ms | 4108kb | C++14 | 978b | 2024-10-03 15:03:11 | 2024-10-03 15:03:16 |
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)
{
if(mp.find(1ll*r*N+l)!=mp.end()) return mp[1ll*r*N+l];
int x;
printf("? %d %d\n",l,r);
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)/2,lmid,x=query(l,r),y;
if(l+1==r)
{
if(x==l) answer(r);
else answer(l);
return;
}
if(x<=mid)
{
lmid=(r-l)*3.0/4+l;
if(lmid==r) lmid--;
y=query(l,lmid);
if(x==y) solve(l,lmid);
else solve(lmid+1,r);
}
else
{
lmid=(r-l)*1.0/4+l;
if(lmid==l) lmid++;
y=query(lmid,r);
if(x==y) solve(lmid,r);
else solve(l,lmid-1);
}
return;
}
int T,n;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
solve(1,n);
mp.clear();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3788kb
input:
3 5 3 3 3 2 6 6 6 3 4 3 3 2
output:
? 1 5 ? 1 4 ? 2 4 ? 2 3 ! 4 ? 1 6 ? 2 6 ? 3 6 ! 2 ? 1 4 ? 2 4 ? 2 3 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 140ms
memory: 4108kb
input:
10000 10 2 2 2 2 3 10 10 10 10
output:
? 1 10 ? 1 7 ? 1 5 ? 1 4 ? 1 3 ! 4 ? 1 10 ? 3 10 ? 4 10 ? 5 10
result:
wrong answer Too long queries, n = 10, now length 31 (test case 2)