QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#97256 | #6303. Inversion | ksunhokim | RE | 0ms | 3396kb | C++20 | 1.7kb | 2023-04-16 16:39:41 | 2023-04-16 16:39:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int cnt = 0;
map<pair<int,int>, bool> cache;
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;
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;
}
void merge(vector<int>& arr, int L, int M, int R) {
vector<int> res;
int left = L, right = M+1;
while (left <= M && right <= R) {
if (compare(arr[left], arr[right])) {
res.push_back(arr[left]);
left++;
} else {
res.push_back(arr[right]);
right++;
}
}
while (left <= M) {
res.push_back(arr[left]);
left++;
}
while (right <= R) {
res.push_back(arr[right]);
right++;
}
for (int i=L;i<=R;i++) {
arr[i] = res[i-L];
}
}
int main() {
int n;
cin >> n;
vector<int> A(n);
iota(begin(A), end(A), 0);
sort(begin(A), end(A), [&](int i, int j) { return compare(i,j); });
// auto merge_sort = [&](auto self, int L, int R) -> void {
// if (L == R) {
// return;
// }
// int M = (R+L)/2;
// self(self, L, M);
// self(self, M+1, R);
// merge(A, L, M, R);
// };
// merge_sort(merge_sort, 0, n-1);
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: 0ms
memory: 3396kb
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 1 1 0 1 0 1 0 1 1 1 1 1 0 0 0 0 1 0 1 0 1 1 0 1 1 1 1 1 0 0 1 1 1 0 0 0 1 0 1 1 0 0 0 1 1 0 1 1 1 0 0 0 0 0 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 0 1 1 0 1 0 0 0 0 1 0 1 1 1 0 1 1 1 0 1 0 1 1 0 0 0 1 1 0 1 1 1 1 1 0 0 0 0 1 1 1 0 1 0 0 0 1 1 0 1 0 0 0...
output:
? 2 997 ? 2 996 ? 3 997 ? 3 996 ? 997 1993 ? 997 1992 ? 998 1993 ? 998 1992 ? 2 1993 ? 2 1992 ? 3 1993 ? 3 1992 ? 1 2 ? 2 3 ? 2 4 ? 3 4 ? 2 5 ? 3 5 ? 2 1991 ? 3 1991 ? 2 1990 ? 3 1990 ? 2 1989 ? 3 1989 ? 2 1988 ? 3 1988 ? 2 1987 ? 3 1987 ? 2 6 ? 3 6 ? 2 1986 ? 3 1986 ? 2 7 ? 3 7 ? 2 1985 ? 3 1985 ? ...