QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#620356 | #8939. Permutation | zzpcd# | WA | 1ms | 3704kb | C++23 | 1.1kb | 2024-10-07 17:42:10 | 2024-10-07 17:42:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n;
const double k = 0.618;
int ask(int l, int r) {
if(l == r) return -1;
cout << "? " << l << ' ' << r << endl;
int x;
cin >> x;
return x;
}
void answer(int x) {
cout << "! " << x << endl;
return;
}
void solve(int l, int r, int sec = -1) {
if(l == r) {
answer(l);
return;
}
if(sec == -1) sec = ask(l, r);
if(l + 1 == r) {
answer(l == sec ? r : l);
return;
}
int mid = (r - l + 1) * k;
if(l + mid - 1 >= sec) {
mid = l + mid - 1;
int u = ask(l, mid);
if(u == sec) {
return solve(l, mid, sec);
} else return solve(mid + 1, r, -1);
} else {
mid = r - mid + 1;
int u = ask(mid, r);
if(u == sec) {
return solve(mid, r, sec);
} else return solve(l, mid - 1, -1);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while(T--) {
int n;
cin >> n;
solve(1, n);
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3704kb
input:
3 5 3 2 5 6 6 5 3 1 4 3 3
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 4 6 ? 1 3 ? 1 2 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3700kb
input:
10000 10 2 2 3 5 5 10 10 10 8 5 7 10 5 1 10 9 8 10 4 4 6 2 1
output:
? 1 10 ? 1 6 ? 1 3 ? 4 6 ? 4 5 ! 4 ? 1 10 ? 5 10 ? 8 10 ? 5 7 ? 6 7 ! 6 ? 1 10 ? 1 6 ? 7 10 ? 9 10 ? 7 8 ! 7 ? 1 10 ? 1 6 ? 4 6 ? 1 3 ? 1 2 ! 2
result:
wrong answer Wrong prediction (test case 4)