QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#642826 | #8939. Permutation | Wolam# | WA | 7ms | 3656kb | C++20 | 1.4kb | 2024-10-15 16:27:37 | 2024-10-15 16:27:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
map<pair<int,int>,int> mp;
int ask(int l,int r)
{
if(mp[{l,r}])
{
return mp[{l,r}];
}
cout<<"? "<<l<<" "<<r<<endl;
int pos;
cin>>pos;
return mp[{l,r}]=pos;
}
int query(int l,int r)
{
if(l==r)
{
return l;
}
else if(r-l+1==2)
{
int p=ask(l,r);
if(p==l)
{
return r;
}
else
{
return l;
}
}
else
{
int p=ask(l,r);
int mid=(l+(r-l+1)/3);
if(p>=mid&&p<=r)//[l,mid-1] [mid,r]
{
if(ask(mid,r)==p)
{
return query(mid,r);
}
else
{
return query(l,mid-1);
}
}
else//[l,mid] [mid+1,r]
{
mid=(r-(r-l+1)/3);
if(ask(l,mid)==p)
{
return query(l,mid);
}
else
{
return query(mid+1,r);
}
}
}
}
void solve(void)
{
mp.clear();
int n;
cin>>n;
int ans=query(1,n);
cout<<"! "<<ans<<endl;
}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
input:
3 5 3 3 3 3 6 6 3 1 4 3 3 3
output:
? 1 5 ? 2 5 ? 3 5 ? 3 4 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 2 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 7ms
memory: 3580kb
input:
10000 10 2 2 2 2 2
output:
? 1 10 ? 1 7 ? 1 5 ? 2 5 ? 2 4 ? 2 3
result:
wrong answer Too many queries , n = 10 , now_q 6 (test case 1)