QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#541801 | #8939. Permutation | ucup-team1264# | WA | 1ms | 3596kb | C++20 | 2.1kb | 2024-08-31 20:58:47 | 2024-08-31 20:58:50 |
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 li = i, lv = i;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<double> dist(0, 1);
while (l < r) {
if (dist(rng) < 1.0 / 2.5) {
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;
li = i, lv = i;
continue;
}
int m = (l + r) / 2;
if (li < l) {
int tv = query(li, m);
if (tv == lv) {
r = m;
} else {
l = m + 1;
}
} else {
int tv = query(m, li);
if (tv == lv) {
l = m + 1;
} else {
r = m;
}
}
}
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();
};
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3596kb
input:
3 5 3 3 5 6 6 3 6
output:
? 1 5 ? 3 5 ? 4 5 ! 4 ? 1 6 ? 3 6 ? 2 6 ! 3
result:
wrong answer Wrong prediction (test case 2)