QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#541732 | #8939. Permutation | ucup-team1264# | WA | 1ms | 3540kb | C++20 | 2.3kb | 2024-08-31 20:44:36 | 2024-08-31 20:45:00 |
Judging History
answer
// https://www.youtube.com/watch?v=R0P_f0gXXqs
// I could feel your heartbeat
// I could feel somewhere you’re looking down
// ‘Cause it’s you who I’m loving
// And it’s you that I want in need
#ifndef ONLINE_JUDGE
#include "templates/debug.hpp"
#else
#define debug(...)
#endif
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
#define int i64
int query(int l, int r) {
if (l == r) return -1;
cout << "? " << l << " " << r << endl;
cin >> l; return l;
}
int answer(int x) {
cout << "! " << x << endl;
return x;
}
// [5, 10, 8, 17, 19, 9, 18, 4, 2, 3, 15, 16, 14, 13, 12, 11, 1, 6, 7, 20]
void solve() {
int n; cin >> n;
int i = query(1, n);
if (n == 2) {
if (i == 1) answer(2);
else answer(1);
return;
}
int left;
if (i - 1 < n - i) left = query(1, i) == i;
else left = query(i, n) != i;
int l, r;
if (left) l = 1, r = i - 1;
else l = i + 1, r = n;
int ll = i, lr = i, lv = i;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<double> dist(0, 1);
int round = 1;
while (l < r) {
if (round == 0) {
int i = query(l, r);
int left;
if (i - l < r - i) left = query(l, i) == i;
else left = query(i, r) != i;
if (left) r = i - 1;
else l = i + 1;
ll = i, lr = i, lv = i;
round ^= 1;
continue;
}
int m = (l + r) / 2;
if (lr < l) {
int tv = query(ll, m);
if (tv == lv) {
r = m;
} else {
ll = tv, lr = m, lv = tv;
l = m + 1;
}
} else {
int tv = query(m, lr);
if (tv == lv) {
l = m + 1;
} else {
ll = m + 1, lr = tv, lv = tv;
r = m;
}
}
round ^= 1;
}
answer(l);
}
#undef int
// Make bold hypotheses and verify carefully
int main() {
// cin.tie(nullptr);
// ios::sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
};
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3540kb
input:
3 5 3 3 3 6 6 3 3 3 4 3 3
output:
? 1 5 ? 3 5 ? 3 4 ! 4 ? 1 6 ? 3 6 ? 1 3 ? 1 3 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3540kb
input:
10000 10 2 1 2 3 3
output:
? 1 10 ? 1 2 ? 2 6 ? 3 6 ? 3 5 ? 4 5
result:
wrong answer Too many queries , n = 10 , now_q 6 (test case 1)