QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#97301 | #6303. Inversion | ksunhokim | RE | 1ms | 3260kb | C++20 | 1.4kb | 2023-04-16 17:17:16 | 2023-04-16 17:17:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int cnt = 0;
map<pair<int,int>, bool> cache;
vector<int> hidden = {4,3,1,2,5};
int query(int l, int r) {
if (l == r)
return 0;
if (cache.count({l,r}))
return cache[{l,r}];
cnt ++;
assert(cnt <= 4e4);
cout << "? " << l + 1 << " " << r + 1 << endl;
int res;
cin >> res;
#ifdef HIDDEN
int rr = 0;
for (int i=l;i<=r;i++){
for (int j=l;j<=i;j++){
if (hidden[j] > hidden[i]) {
rr++;
}
}
}
res = rr%2;
#endif
return cache[{l,r}] = res;
}
bool compare(int i, int j) {
if (i > j)
return !compare(j,i);
if (i == j) {
return false;
}
if (i == j-1) {
return query(i,j);
}
return (query(i, j) - query(i, j-1) - query(i+1, j) + query(i+1, j-1) + 8)%2;
}
int main() {
int n;
cin >> n;
vector<int> A(n);
iota(begin(A), end(A), 0);
for (int i=1;i<n;i++) {
int ng = -1, ok = i;
while (ok-ng > 1) {
int m = (ok+ng)/2;
if (compare(A[i], A[m])) {
ok = m;
} else {
ng = m;
}
}
int tmp = A[i];
for (int j=i;j>=ok+1;j--){
A[j] = A[j-1];
}
A[ok] = tmp;
}
reverse(begin(A), end(A));
vector<int> ans(n);
for (int i=0;i<n;i++) ans[A[i]] = i;
cout << "! ";
for (int i=0;i<n;i++){
cout << ans[i] + 1 << " ";
}
cout << endl;
}
// 2 1
// 3 1 2
//
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3260kb
input:
3 0 1 0
output:
? 1 2 ? 2 3 ? 1 3 ! 2 3 1
result:
ok OK, guesses=3
Test #2:
score: -100
Dangerous Syscalls
input:
1993 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 1 0 0 0 1 0 0 1 1 1 0 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 0 0 0 0 1 0 1 1 0 1 1 1 0 0 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 0 0 1 1 1 0 1 0 0 0 1 0 0 1 0 1 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 0 0 0 1 0...
output:
? 1 2 ? 2 3 ? 2 4 ? 3 4 ? 3 5 ? 4 5 ? 2 5 ? 1 5 ? 1 4 ? 2 6 ? 3 6 ? 1 6 ? 5 6 ? 2 7 ? 3 7 ? 6 7 ? 5 7 ? 1 8 ? 1 7 ? 2 8 ? 3 8 ? 4 8 ? 4 7 ? 2 9 ? 3 9 ? 6 9 ? 6 8 ? 7 9 ? 7 8 ? 1 9 ? 9 10 ? 6 10 ? 7 10 ? 5 10 ? 5 9 ? 8 10 ? 8 9 ? 9 11 ? 10 11 ? 5 11 ? 6 11 ? 1 11 ? 1 10 ? 2 11 ? 2 10 ? 11 12 ? 8 12 ?...