QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#300427 | #6303. Inversion | mendicillin2# | WA | 71ms | 30832kb | C++17 | 1.6kb | 2024-01-08 11:09:08 | 2024-01-08 11:09:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
using ll = int64_t;
const int N = 2010;
int id[N], a[N], ok[N][N], f[N][N];
inline bool qry(int l, int r) {
if (ok[l][r]) return f[l][r];
cout << "? " << l << ' ' << r << endl;
bool cur;
cin >> cur;
f[l][r] = cur;
ok[l][r] = 1;
return cur;
}
int ni[N], t[N];
inline int lowbit(int x) { return x & (-x); }
inline void add(int x, int r) {
for (int i = x; i <= r; i += lowbit(i)) t[i] ^= 1;
}
inline bool sum(int x) {
bool now = 0;
for (int i = x; i; i -= lowbit(i)) now ^= t[i];
return now;
}
inline void build(int r) {
for (int i = 1; i <= r; i ++) t[i] = 0;
for (int i = r; i >= 1; i --) { ni[i] = sum(a[i]); add(a[i], r); }
}
inline bool check(int p, int x) {
if (id[p] + 1 == x) return !qry(id[p], x);
int a1 = qry(id[p], x), a2 = qry(id[p] + 1, x), a3 = ni[id[p]], a4 = ni[id[p] + 1];
return !(a1 ^ a2 ^ a3 ^ a4);
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
cout << fixed << setprecision(20);
int n;
cin >> n;
id[1] = 1;
a[1] = 1;
for (int i = 2; i <= n; i ++) {
int l = 1, r = i - 1, ans = 0;
while (l <= r) {
int mid = (l + r) >> 1;
if (check(mid, i)) { ans = mid; l = mid + 1; }
else r = mid - 1;
}
for (int j = i - 1; j > ans; j --) {
a[id[j]] = j + 1;
id[j + 1] = id[j];
}
id[ans + 1] = i;
a[i] = ans + 1;
build(i);
}
cout << "! ";
for (int i = 1; i < n; i ++) cout << a[i] << ' ';
cout << a[n] << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3588kb
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: 71ms
memory: 30832kb
input:
1993 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 1 0 0 1 0 0 1 1 1 0 0 1 1 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 1 1 0 1 1 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 1 1 0 1 1 1 1 0 1 1 1 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 1 1 0 0 0 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 0 1 0 1 1 0 1 1 0 1 0 0 0 1 0 1 0...
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4 ? 3 4 ? 2 5 ? 3 5 ? 1 5 ? 2 6 ? 3 6 ? 4 6 ? 5 6 ? 2 7 ? 3 7 ? 5 7 ? 6 7 ? 2 8 ? 3 8 ? 5 8 ? 6 8 ? 7 8 ? 1 9 ? 2 9 ? 8 9 ? 7 9 ? 1 10 ? 2 10 ? 3 10 ? 4 10 ? 1 11 ? 2 11 ? 9 11 ? 10 11 ? 8 11 ? 5 11 ? 6 11 ? 1 12 ? 2 12 ? 8 12 ? 9 12 ? 7 12 ? 5 13 ? 6 13 ? 9 13 ? 10 13 ? 12 13 ...
result:
wrong answer Wa.