QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#555540 | #8939. Permutation | Insert_Username_Here | WA | 1ms | 3640kb | C++20 | 1.1kb | 2024-09-10 03:37:21 | 2024-09-10 03:37:22 |
Judging History
answer
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
// const ll mod = 1e9 + 7;
// #include <brawlstars>
// FOR PAIN OR FOR GLORYYY ELLL PRIMOOOOOO
const double rt = 0.61803398875;
int qry(int l, int r) {
int ans;
cout << "? " << l << " " << r << "\n";
cout.flush();
cin >> ans;
return ans;
}
int f(int l, int r) {
int mid, pos = qry(l, r);
while(r - l > 2) {
mid = l + (r - l) * rt;
if(pos <= mid) {
(qry(l, mid) == pos) ? r = mid : l = mid + 1;
if(l > mid) pos = qry(l, r);
} else {
mid = r - (r - l) * rt;
(qry(mid, r) == pos) ? l = mid : r = mid - 1;
if(r < mid) pos = qry(l, r);
}
}
if(r - l == 1) return (l == pos ? r : l);
if(l == pos) return (r == qry(r - 1, r) ? r - 1 : r);
if(r == pos) return (l == qry(l, l + 1) ? l + 1 : l);
return (l + 1 == qry(l, l + 1) ? l : r);
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while(t--) {
int n;
cin >> n;
int ans = f(1, n);
cout << "! " << ans << "\n";
cout.flush();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3640kb
input:
3 5 3 2 5 6 6 6 3
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 2 6 ? 3 6 ? 2 2
result:
wrong answer Integer 2 violates the range [3, 6] (test case 2)