QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#554451 | #8939. Permutation | andrewgopher | WA | 141ms | 3704kb | C++14 | 2.0kb | 2024-09-09 11:20:40 | 2024-09-09 11:20:40 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define int long long
int query(int l, int r){
cout << "? " << min(l,r) << " " << max(l,r) << endl;
int x;
cin>>x;
return x;
}
int quarter(int l, int r){
if (r-l+1==1){
return l;
}
int second = query(l,r);
int mid = (l+r)/2;
if (r-l>1){
mid = (l+r-rand()%2)/2;
}
//ranges are [l,mid] and [mid+1,r]
bool isL;//is [l,mid] otherwise [mid+1,r]
if (second<=mid){
if (l==mid){
isL = false;
} else {
isL = query(l,mid)==second;
}
} else {
if (mid+1==r){
isL = true;
} else {
isL = query(mid+1,r)!=second;
}
}
int curL, curR;
if (isL){
curL = l;
curR = mid;
} else {
curL = mid+1;
curR = r;
}
if (curL==curR){
return curL;
}
int midQ = (curL+curR)/2;
if (curR-curL>1){
midQ = (curL+curR-rand()%2)/2;
}
//ranges are [curL,midQ] and [midQ+1,curR]
bool isLQ;
if (second < curL){
isLQ = query(second,midQ) == second;
} else if (second >= curL && second <= midQ){
if (curL==midQ){
isLQ = false;
} else{
isLQ = query(curL,midQ)==second;
}
} else if (second >= midQ+1 && second <= curR){
if (midQ+1==curR){
isLQ = true;
} else {
isLQ = query(midQ+1,curR) != second;
}
} else if (second>curR) {
isLQ = query(midQ+1,second)!=second;
} else {
assert(false);
}
if (isLQ) {
return quarter(curL,midQ);
} else {
return quarter(midQ+1,curR);
}
}
void solve() {
int n;
cin >> n;
int ans = quarter(1,n);
cout << "! " << ans << endl;
}
signed main() {
int t;
cin>>t;
while (t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3704kb
input:
3 5 3 3 3 3 6 6 5 6 3 4 3 3
output:
? 1 5 ? 3 5 ? 3 4 ? 3 4 ! 4 ? 1 6 ? 4 6 ? 2 6 ? 2 3 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: 0
Accepted
time: 87ms
memory: 3568kb
input:
10000 10 2 2 3 5 10 10 10 8 7 10 5 1 5 6 10 4 4 5 2 2 10 10 6 6 3 2 10 3 3 5 2 10 1 5 1 6 7 10 1 3 1 8 8 10 2 4 4 9 10 3 3 3 3 3 10 4 1 7 9 10 8 7 8 4 5 10 4 1 5 9 10 7 8 7 4 10 5 1 7 8 8 10 8 8 8 8 9 10 2 1 2 7 10 6 6 7 10 10 10 1 3 1 8 8 10 7 9 5 1 2 10 7 8 7 4 4 10 3 4 4 10 10 10 4 4 4 4 10 8 7 7...
output:
? 1 10 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 10 ? 6 10 ? 8 10 ? 6 7 ! 6 ? 1 10 ? 1 5 ? 5 7 ? 6 7 ! 7 ? 1 10 ? 1 5 ? 4 5 ? 1 3 ? 2 3 ! 3 ? 1 10 ? 6 10 ? 4 10 ? 1 3 ? 2 3 ! 1 ? 1 10 ? 1 5 ? 3 5 ? 1 2 ! 1 ? 1 10 ? 1 5 ? 1 8 ? 6 8 ? 6 7 ! 8 ? 1 10 ? 1 5 ? 1 8 ? 6 8 ? 7 8 ! 7 ? 1 10 ? 1 5 ? 2 8 ? 9 10 ! 10 ? 1 10 ? ...
result:
ok Correct (10000 test cases)
Test #3:
score: 0
Accepted
time: 110ms
memory: 3636kb
input:
10000 3 1 2 11 5 5 5 5 5 2 2 19 3 4 3 13 14 12 11 7 5 7 5 2 3 3 3 19 6 6 7 1 2 1 2 2 15 11 11 11 11 12 10 14 1 1 1 1 2 3 16 4 4 1 8 7 8 3 3 2 19 13 17 6 5 5 4 2 2 4 1 2 3 7 2 2 2 2 3 2 2 17 1 1 2 8 9 6 14 9 9 9 9 8 9 20 9 3 9 13 14 13 6 4 4 5 18 7 7 7 7 5 7 8 8 6 8 3 8 6 7 6 3 16 10 10 10 10 10 6 1 ...
output:
? 1 3 ? 1 2 ! 3 ? 1 11 ? 1 6 ? 4 6 ? 4 6 ? 5 6 ! 6 ? 1 2 ! 1 ? 1 19 ? 1 9 ? 3 14 ? 10 14 ? 13 14 ? 12 13 ? 10 11 ! 10 ? 1 7 ? 4 7 ? 2 5 ? 2 3 ! 3 ? 1 3 ? 2 3 ! 2 ? 1 19 ? 1 9 ? 6 9 ? 1 5 ? 1 2 ? 1 3 ! 3 ? 1 2 ! 1 ? 1 15 ? 9 15 ? 9 12 ? 9 12 ? 11 12 ? 10 11 ! 9 ? 1 14 ? 1 7 ? 1 4 ? 1 4 ? 1 2 ? 1 3 ! ...
result:
ok Correct (10000 test cases)
Test #4:
score: 0
Accepted
time: 141ms
memory: 3628kb
input:
10000 47 23 23 19 11 9 11 5 6 14 8 8 8 8 9 8 25 6 12 6 13 13 15 7 4 2 4 9 2 2 2 2 27 27 27 27 27 26 24 23 21 7 7 6 5 5 5 5 43 41 37 21 7 8 5 3 3 22 6 4 14 20 20 21 34 29 25 29 17 17 17 17 16 42 20 20 20 20 20 19 17 47 21 21 21 21 21 22 19 19 41 25 25 30 33 34 33 38 19 17 17 16 12 12 21 14 14 14 14 1...
output:
? 1 47 ? 1 23 ? 13 23 ? 1 12 ? 7 12 ? 4 11 ? 4 6 ? 5 6 ! 4 ? 1 14 ? 8 14 ? 8 11 ? 8 11 ? 8 9 ? 8 10 ! 10 ? 1 25 ? 1 12 ? 6 18 ? 13 18 ? 13 15 ? 14 15 ! 14 ? 1 7 ? 1 4 ? 4 5 ! 5 ? 1 9 ? 1 4 ? 1 2 ? 1 2 ! 1 ? 1 27 ? 15 27 ? 22 27 ? 22 27 ? 25 27 ? 24 27 ? 22 23 ! 22 ? 1 21 ? 1 10 ? 6 10 ? 1 5 ? 3 5 ? ...
result:
ok Correct (10000 test cases)
Test #5:
score: 0
Accepted
time: 104ms
memory: 3572kb
input:
10000 100 47 5 47 61 53 68 71 71 71 71 9 2 2 2 2 2 53 46 35 14 6 6 6 6 6 33 3 16 16 31 31 30 32 82 60 42 60 29 29 28 23 22 24 26 88 39 8 39 59 59 59 59 59 60 71 24 29 29 59 59 59 59 60 60 92 52 52 56 88 88 88 88 89 88 24 11 11 9 5 5 5 5 66 51 51 66 45 43 45 39 40 39 92 43 43 38 20 20 20 20 20 19 48 ...
output:
? 1 100 ? 1 50 ? 47 75 ? 51 75 ? 51 62 ? 61 68 ? 69 75 ? 69 71 ? 70 71 ? 70 71 ! 70 ? 1 9 ? 1 5 ? 1 3 ? 1 3 ? 2 3 ! 3 ? 1 53 ? 27 53 ? 14 46 ? 1 13 ? 1 6 ? 4 6 ? 4 6 ? 5 6 ! 5 ? 1 33 ? 1 16 ? 3 25 ? 26 33 ? 30 33 ? 30 31 ? 32 33 ! 33 ? 1 82 ? 42 82 ? 22 60 ? 22 41 ? 22 31 ? 27 31 ? 22 26 ? 22 23 ? 2...
result:
ok Correct (10000 test cases)
Test #6:
score: -100
Wrong Answer
time: 71ms
memory: 3576kb
input:
10000 50 10 10 10 10 7 10 6 5 50 11 11 9 18 16 22 23 23 50 44 40 44 20 20 21 25 25 50 24 14 29 45 45 45 45 46 50 50 50 50 50 50 49 47 47 50 36 39 23 12 12 11 8 8 50 29 36 20 13 12 6 3 3 50 30 42 22 1 1 1 1 2 50 25 15 25 30 30 31 27 26 50 18 20 18 30 27 34 37 36 50 9 9 9 9 9 7 13 13 50 26 43 26 17 17...
output:
? 1 50 ? 1 25 ? 1 13 ? 1 13 ? 7 13 ? 4 10 ? 4 6 ? 5 6 ! 4 ? 1 50 ? 1 25 ? 1 13 ? 14 25 ? 14 19 ? 18 22 ? 23 25 ? 23 24 ! 24 ? 1 50 ? 26 50 ? 13 44 ? 13 25 ? 20 25 ? 20 22 ? 23 25 ? 24 25 ! 24 ? 1 50 ? 1 25 ? 24 38 ? 39 50 ? 45 50 ? 45 47 ? 45 47 ? 45 46 ! 47 ? 1 50 ? 26 50 ? 39 50 ? 39 50 ? 45 50 ? ...
result:
wrong answer Too long queries, n = 50, now length 151 (test case 5739)