QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#555538 | #8939. Permutation | Insert_Username_Here | WA | 1ms | 3648kb | C++20 | 1.1kb | 2024-09-10 03:35:10 | 2024-09-10 03:35:10 |
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 + 1) * rt - 1;
if(pos <= mid) {
(qry(l, mid) == pos) ? r = mid : l = mid + 1;
if(l > mid) pos = qry(l, r);
} else {
mid = r - (r - l + 1) * rt + 1;
(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: 100
Accepted
time: 1ms
memory: 3640kb
input:
3 5 3 2 5 6 6 3 1 4 3 3 2
output:
? 1 5 ? 1 3 ? 4 5 ! 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: 1ms
memory: 3648kb
input:
10000 10 2 2 3 5 5 10 10 10 10 7
output:
? 1 10 ? 1 6 ? 1 3 ? 4 6 ? 4 5 ! 4 ? 1 10 ? 4 10 ? 6 10 ? 7 10 ? 6 6
result:
wrong answer Integer 6 violates the range [7, 10] (test case 2)