QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#181220 | #6303. Inversion | ykpcx# | WA | 79ms | 19344kb | C++17 | 1.6kb | 2023-09-16 16:50:02 | 2023-09-16 16:50:03 |
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) {
int res = rkl > rkr ? 1 : -1 ;
// printf("left = %d, right = %d mid = %d\n", left, right, mid);
// printf("l = %d, r = %d, res = %d rkl = %d rkr = %d\n", l, r, res, rkl, rkr);
return res;
}
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 19344kb
input:
3 0 1 0
output:
? 1 2 ? 2 3 ? 1 3 ! 2 3 1
result:
ok OK, guesses=3
Test #2:
score: -100
Wrong Answer
time: 79ms
memory: 19344kb
input:
1993 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 1 0 0 1 0 1 1 1 1 0 1 1 1 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 1 1 1 0 0 1 0 1 0 0 0 0 0 1 1 1 1 0 0 1 0 0 1 0 0 1 1 0 0 1 1 1 1 1 0 1 1 1 1 0 1 0 0 0 0 1 1 1 1 0 1 0 0 0 0 0 1 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 0...
output:
? 1 2 ? 2 3 ? 3 4 ? 2 4 ? 3 5 ? 4 5 ? 5 6 ? 4 6 ? 6 7 ? 5 7 ? 1 6 ? 2 7 ? 2 6 ? 3 7 ? 3 6 ? 6 8 ? 7 8 ? 4 7 ? 5 8 ? 6 9 ? 7 9 ? 4 8 ? 5 9 ? 8 9 ? 3 9 ? 4 10 ? 4 9 ? 5 10 ? 9 10 ? 3 10 ? 4 11 ? 10 11 ? 9 11 ? 6 11 ? 7 12 ? 7 11 ? 11 12 ? 10 12 ? 8 11 ? 9 12 ? 6 12 ? 7 13 ? 12 13 ? 8 12 ? 9 13 ? 4 13 ...
result:
wrong output format Unexpected end of file - int32 expected