QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#817557 | #8939. Permutation | KKT89 | WA | 1ms | 3588kb | C++20 | 2.1kb | 2024-12-17 03:43:06 | 2024-12-17 03:43:07 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int q;
cin >> q;
while (q--) {
int n;
cin >> n;
int l = 1, r = n;
int second = -1;
while (l < r) {
if (second == -1) {
cout << "? " << l << " " << r << endl;
cin >> second;
}
if (l + 1 == r) {
if (l == second) {
l += 1;
}
break;
}
int mid = (l + r) / 2;
if (second <= mid) {
cout << "? " << l << " " << mid << endl;
int res;
cin >> res;
if (res == second) {
r = mid;
} else {
l = mid + 1;
int mid2 = (l + r) / 2;
cout << "? " << second << " " << mid2 << endl;
cin >> res;
if (res == second) {
r = mid2;
} else {
l = mid2 + 1;
}
second = -1;
}
} else {
cout << "? " << mid << " " << r << endl;
int res;
cin >> res;
if (res == second) {
l = mid;
} else {
r = mid - 1;
int mid2 = (l + r) / 2;
cout << "? " << mid2 << " " << second << endl;
cin >> res;
if (res == second) {
l = mid2;
} else {
r = mid2 - 1;
}
second = -1;
}
}
}
cout << "! " << l << endl;
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3588kb
input:
3 5 3 2 3 6 6 3 6 1 4 3 3 2
output:
? 1 5 ? 1 3 ? 3 4 ! 4 ? 1 6 ? 3 6 ? 1 6 ? 1 2 ! 2 ? 1 4 ? 2 4 ? 2 3 ? 3 4
result:
wrong answer Too many queries , n = 4 , now_q 4 (test case 3)