QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#97252 | #6303. Inversion | ksunhokim | RE | 2ms | 3276kb | C++20 | 1.7kb | 2023-04-16 16:38:39 | 2023-04-16 16:38:41 |
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: 2ms
memory: 3276kb
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 0 1 1 0 0 1 0 0 0 1 1 0 1 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 1 0 0 0 0 0 0 1 1 0 1 1 1 0 1 0 0 1 0 1 1 1 0 0 0 1 1 0 1 0 0 0 0 0 0 1 0 1 1 0 1 1 1 1 0 0 1 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 1 0 0 0 0 1 1 0 0 0 1 0 0 1 1 1 0 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 1 1 1 1...
output:
? 1 2 ? 3 4 ? 2 4 ? 2 3 ? 5 6 ? 7 8 ? 6 8 ? 6 7 ? 5 7 ? 4 8 ? 4 7 ? 5 8 ? 3 8 ? 3 7 ? 2 8 ? 2 7 ? 2 6 ? 2 5 ? 3 6 ? 3 5 ? 1 6 ? 1 5 ? 9 10 ? 11 12 ? 9 12 ? 9 11 ? 10 12 ? 10 11 ? 13 14 ? 15 16 ? 13 16 ? 13 15 ? 14 16 ? 14 15 ? 12 13 ? 12 16 ? 12 15 ? 12 14 ? 9 15 ? 9 14 ? 10 15 ? 10 14 ? 11 15 ? 11 ...