QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#541630 | #8939. Permutation | ucup-team3734# | WA | 6ms | 3612kb | C++23 | 1.3kb | 2024-08-31 20:16:12 | 2024-08-31 20:16:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef double lf;
int ask(int l, int r) {
cout << "? " << l << " " << r << endl;
int res;
cin >> res;
return res;
}
void answer(int x) {
cout << "! " << x << endl;
}
void go(int l, int r, optional<int> pos) {
if (l == r) {
answer(l);
return;
}
if (!pos.has_value()) {
pos = ask(l, r);
}
if (l + 1 == r) {
answer(*pos == l ? r : l);
return;
}
int len = (int) ceil((r - l + 1) * 0.6135117904356906);
int m = (l + r) / 2;
if (pos <= m) {
m = l + len - 1;
int x = ask(l, m);
if (x == *pos) {
go(l, m, x);
} else {
go(m + 1, r, nullopt);
}
} else {
m = r - len + 1;
int x = ask(m, r);
if (x == *pos) {
go(m, r, x);
} else {
go(l, m - 1, nullopt);
}
}
}
void solve() {
int n;
cin >> n;
go(1, n, nullopt);
}
signed main() {
#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
int t = 1;
cin >> t;
for (int i = 0; i < t; i++) {
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
3 5 3 3 3 2 6 6 3 1 4 3 3 2
output:
? 1 5 ? 1 4 ? 2 4 ? 2 3 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 2 4 ? 2 3 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 6ms
memory: 3556kb
input:
10000 10 2 2 2 2 3 10 10 10 10 7 10 5 5 5 4 10 4 4 4 4 4
output:
? 1 10 ? 1 7 ? 1 5 ? 1 4 ? 1 3 ! 4 ? 1 10 ? 4 10 ? 6 10 ? 7 10 ! 6 ? 1 10 ? 1 7 ? 3 7 ? 3 6 ! 7 ? 1 10 ? 1 7 ? 1 5 ? 2 5 ? 3 5 ? 3 4
result:
wrong answer Too many queries , n = 10 , now_q 6 (test case 4)