QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#801612 | #8939. Permutation | Infinite_Loopers# | WA | 4ms | 3672kb | C++23 | 1.1kb | 2024-12-07 04:00:42 | 2024-12-07 04:00:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
//22.43
ll q(ll l, ll r) {
if(l==r) return l;
cout<<"? "<<l<<" "<<r<<endl;
cin>>l;
return l;
}
ll s(ll l, ll r, ll min2) {
if(r==l+1) return l+r-min2;
if(l==r) return l;
ll mid = l+(r-l)/2;
if(min2<=mid) {
ll r0 = l+(r-l)*0.618;
ll a = q(l, r0);
if(a==min2) {
return s(l, r0, min2);
}
else {
if(r0==r) return r;
return s(r0+1, r, q(r0+1, r));
}
}
else {
ll l0 = r-(r-l)*0.618;
ll a = q(l0, r);
if(a==min2) {
return s(l0, r, min2);
}
else {
if(l0==l) return l;
return s(l, l0-1, q(l, l0-1));
}
}
}
void solve() {
ll n;
cin >> n;
ll r = s(1, n, q(1, n));
cout <<"! "<< r << endl;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
ll n;
cin>>n;
for (int i = 0; i < n; ++i) {
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3664kb
input:
3 5 3 2 5 6 6 6 3 4 3 3 2
output:
? 1 5 ? 1 3 ? 4 5 ! 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: 4ms
memory: 3672kb
input:
10000 10 2 2 2 1 3 10 10 10 10 7 10 5 1 10 9 10 4 4 4 4 4
output:
? 1 10 ? 1 6 ? 1 4 ? 1 2 ? 3 4 ! 4 ? 1 10 ? 4 10 ? 6 10 ? 7 10 ! 6 ? 1 10 ? 1 6 ? 7 10 ? 8 10 ! 7 ? 1 10 ? 1 6 ? 2 6 ? 2 4 ? 2 4 ? 2 4
result:
wrong answer Too many queries , n = 10 , now_q 6 (test case 4)