QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#181206 | #6303. Inversion | ykpcx# | WA | 2ms | 19444kb | C++17 | 1.5kb | 2023-09-16 16:37:48 | 2023-09-16 16:37:49 |
Judging History
answer
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
const int N = 2e3 + 5;
int n;
int len;
int a[N];
int vis[N][N];
int query(int l, int r) {
if (l == r) return 0;
if (~vis[l][r]) return vis[l][r];
printf("? %d %d\n", l, r);
fflush(stdout);
int x;
cin >> x;
return vis[l][r] = x;
}
int cmp(int l, int r) {
if (r - l == 1) {
return (query(l, r) ? 1 : -1);
}
int left = query(l, r - 1);
int right = query(l + 1, r);
int mid = query(l + 1, r - 1);
int rkl = left - mid;
int len = r - l + 1;
int rkr = len - (right - mid);
if (rkl != rkr) return rkl > rkr ? 1 : -1;
int all = query(l, r);
return (left ^ right ^ mid ^ all ? 1 : -1);
}
void insert(int idx, int x) {
len++;
int i = len - 1;
for (;i != idx; i--) a[i] = a[i-1];
a[i] = x;
}
void solve() {
cin >> n;
memset(vis, -1, sizeof(vis));
a[0] = 1;
len = 1;
for (int i = 2; i <= n; i++) {
int lb = -1, rb = len;
while (rb - lb > 1) {
int mid = (lb + rb) / 2;
if (cmp(a[mid], i) == -1)
lb = mid;
else
rb = mid;
}
// printf("rb = %d\n", rb);
insert(rb, i);
}
vector<int> ans(n + 1);
for (int i = 0; i < n; i++) {
ans[a[i]] = i + 1;
}
printf("!");
for (int i = 1; i <= len; i++) {
printf(" %d", ans[i]);
}
puts("");
}
int main() {
ios::sync_with_stdio(false);
// cin.tie(0);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 19444kb
input:
3 0 1
output:
? 1 2 ? 2 3 ! 1 3 2
result:
wrong answer Wa.