QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#398839 | #6303. Inversion | gqf123 | WA | 1ms | 3644kb | C++20 | 1.5kb | 2024-04-25 19:00:06 | 2024-04-25 19:00:08 |
Judging History
answer
#include<iostream>
#include<vector>
#include<algorithm>
#include<random>
using namespace std;
int vis[2001][2001], ans[2001], tree[2001], n;
inline int query(int l, int r) {
if (l == r)
return 0;
if (~vis[l][r])
return vis[l][r];
cout << "? " << l << ' ' << r << endl;
cin >> vis[l][r];
return vis[l][r];
}
inline int ask(int x, int y) {
if (x == y)
return 0;
if (x + 1 == y)
return query(x, y);
return (query(x, y) - query(x + 1, y) - query(x, y - 1) + query(x + 1, y - 1) + 50) % 2;
}
inline int sum(int p) {
int ans = 0;
for (; p; p ^= p & -p)
ans += tree[p];
return ans;
}
inline void add(int p, int v) {
for (; p <= n; p += p & -p)
tree[p] += v;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
vis[i][j] = -1;
for (int i = 1; i <= n; ++i)
vis[i][i] = 0;
vector<int>o;
for (int i = 1; i <= n; ++i) {
int l = 0, r = o.size(), mid;
for (; l < r;) {
mid = l + r >> 1;
if (ask(o[mid], i))
r = mid;
else
l = mid + 1;
}
o.insert(o.begin() + l, i);
for (int j = 0; j ^ o.size(); ++j)
ans[o[j]] = j + 1;
for (int j = 1; j <= n; ++j) {
tree[j] = 0;
}
add(ans[i], 1);
for (int j = i - 1; j; --j) {
vis[j][i] = (vis[j][i - 1] + i - j - sum(ans[j])) % 2;
add(ans[j], 1);
}
}
cout << "! ";
for (int i = 1; i <= n; ++i)
cout << ans[i] << ' ';
cout << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3644kb
input:
3 0 1 0
output:
? 1 2 ? 2 3 ? 1 3 ! 1 3 2
result:
wrong answer Wa.