QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#613095 | #8939. Permutation | Fork512Hz | WA | 81ms | 3712kb | C++20 | 1.0kb | 2024-10-05 13:34:22 | 2024-10-05 13:34:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pii;
ll query(ll x, ll y)
{
cout << "? " << x << ' ' << y << '\n';
cout.flush();
ll tmp;
cin >> tmp;
return tmp;
}
void answer(ll x)
{
cout << "! " << x << '\n';
cout.flush();
}
void solve(ll l, ll r, ll po)
{
if(r-l == 1)
{
answer(l);
throw 0ll;
}
else if(r-l == 2)
{
if(po == l) answer(l+1);
else if(po == l+1) answer(l);
else answer(2*l+1 - query(l, l+1));
throw 0ll;
}
if(po == -1) po = query(l, r-1);
ll mid = (l+r) / 2;
if((r-l) % 2 && po < mid) mid++;
if(po < mid)
{
ll t = query(l, mid-1);
if(t == po) solve(l, mid, po);
else solve(mid, r, -1);
}
else
{
ll t = query(mid, r-1);
if(t == po) solve(mid, r, po);
else solve(l, mid, -1);
}
}
int main()
{
ll z;
cin >> z;
while(z--)
{
ll n;
cin >> n;
try
{
solve(1, n+1, -1);
}
catch(const ll &e)
{
;
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3644kb
input:
3 5 3 3 3 6 6 5 3 3 4 3 3
output:
? 1 5 ? 3 5 ? 3 4 ! 4 ? 1 6 ? 4 6 ? 1 3 ? 2 3 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: 0
Accepted
time: 81ms
memory: 3712kb
input:
10000 10 2 2 3 5 10 10 10 8 7 10 5 1 10 9 6 10 4 4 4 5 10 10 6 3 5 2 10 3 3 5 2 10 1 5 9 9 10 10 1 3 8 10 6 10 2 4 9 9 9 10 3 3 3 3 10 4 1 7 8 9 10 8 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