QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#441799 | #6303. Inversion | james1BadCreeper# | WA | 45ms | 19296kb | C++17 | 1.2kb | 2024-06-14 18:21:47 | 2024-06-14 18:21:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n, a[N], ord[N], ans[N][N];
int ask(int l, int r) {
if (l >= r) return 0;
if (ans[l][r] != -1) return ans[l][r];
cout << "? " << l << ' ' << r << endl;
return cin >> ans[l][r], ans[l][r];
}
int cmp(int l, int r) {
int num = ask(l, r) ^ ask(l, r - 1) ^ ask(l + 1, r) ^ ask(l + 1, r - 1);
return num == 1;
}
int main(void) {
ios::sync_with_stdio(0);
cin >> n;
memset(ans, -1, sizeof ans);
ord[1] = a[1] = 1;
for (int i = 1; i <= n; ++i) ans[i][i] = 1;
for (int i = 2; i <= n; ++i) {
int l = 0, r = i;
while (l + 1 != r) {
int mid = l + r >> 1;
if (cmp(ord[mid], i)) r = mid; // a[ord[mid]] > a[i]
else l = mid;
}
// a[ord[l]] < a[i]
for (int j = i - 1; j >= r; --j) ord[j + 1] = ord[j];
ord[r] = i;
for (int j = 1; j <= i; ++j) a[ord[j]] = j;
for (int j = i - 1; j >= 1; --j) ans[j][i] = (ans[j + 1][i] ^ (a[j] > a[i]));
for (int j = 1; j < i; ++j) ans[j][i] ^= ans[j][i - 1];
}
cout << "! ";
for (int i = 1; i <= n; ++i) cout << a[i] << ' ';
cout << endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 19288kb
input:
3 0 0 1
output:
? 1 2 ? 1 3 ? 2 3 ! 2 3 1
result:
ok OK, guesses=3
Test #2:
score: -100
Wrong Answer
time: 45ms
memory: 19296kb
input:
1993 0 0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 1 1 1 0 0 1 1 0 0 1 1 1 1 0 0 0 1 0 0 0 0 1 0 1 0 1 0 1 0 1 1 1 1 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 1 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 1 1 0 1 0 1 1...
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4 ? 3 4 ? 2 5 ? 3 5 ? 4 5 ? 5 6 ? 3 6 ? 4 6 ? 5 7 ? 6 7 ? 1 7 ? 2 7 ? 3 7 ? 5 8 ? 6 8 ? 2 8 ? 3 8 ? 7 8 ? 8 9 ? 2 9 ? 3 9 ? 1 9 ? 8 10 ? 9 10 ? 1 10 ? 2 10 ? 7 11 ? 8 11 ? 1 11 ? 2 11 ? 9 11 ? 10 11 ? 7 12 ? 8 12 ? 3 12 ? 4 12 ? 9 12 ? 5 12 ? 6 12 ? 7 13 ? 8 13 ? 12 13 ? 6 13 ?...
result:
wrong answer Wa.