QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#286700 | #6303. Inversion | 000226# | WA | 0ms | 3528kb | C++17 | 1.9kb | 2023-12-18 13:36:21 | 2023-12-18 13:36:21 |
Judging History
answer
#include <bits/stdc++.h>
#define lep(i, l, r) for(int i = (l); i <= (r); i ++)
#define rep(i, l, r) for(int i = (l); i >= (r); i --)
#define debug(...) fprintf (stderr, __VA_ARGS__)
using std :: cin;
using std :: cout;
using std :: endl;
using std :: cerr;
using i64 = long long;
const int P = 998244353;
inline int mod(int x) { return x + (x >> 31 & P); }
inline void sub(int &x, int y) { x = mod(x - y); }
inline void pls(int &x, int y) { x = mod(x + y - P); }
inline int add(int x, int y) { return mod(x + y - P); }
inline int dec(int x, int y) { return mod(x - y); }
inline int power(int x, int k) {
int res = 1; if (k < 0) k += P - 1;
while (k) { if (k & 1) res = 1ll * res * x % P; x = 1ll * x * x % P; k >>= 1; }
return res;
}
int qry (int l, int r) {
if (l == r) return 0;
if (l > r) return 0;
cout << "? " << l << ' ' << r << endl;
int o;
cin >> o;
return o;
}
const int N = 2000 + 5;
int n;
int ans[N], dans[N];
int f[N][N];
inline int query (int l, int r) { // l > r
int o = 0;
if (l > r) std :: swap (l, r), o ^= 1;
if (f[l][r] == -1) f[l][r] = qry (l, r);
if (f[l + 1][r] == -1) f[l + 1][r] = qry (l + 1, r);
if (f[l][r - 1] == -1) f[l][r - 1] = qry (l, r - 1);
if (f[l + 1][r - 1] == -1) f[l + 1][r - 1] = qry (l + 1, r - 1);
return f[l][r] ^ f[l + 1][r] ^ f[l][r - 1] ^ f[l + 1][r - 1] ^ o;
}
int main() {
std :: ios :: sync_with_stdio(false);
srand (time(0));
cin >> n;
lep (i, 1, n) lep (j, 1, n) f[i][j] = -1;
ans[1] = 1;
for (int i = 2; i <= n; i ++) {
int l = 1, r = i - 1, res = 0;
while (l <= r) {
int mid = (l + r) >> 1;
if (query (ans[mid], i)) r = mid - 1;
else res = mid, l = mid + 1;
}
rep (j, i, res + 2) ans[i] = ans[i - 1];
ans[res + 1] = i;
}
lep (i, 1, n) dans[ans[i]] = i;
cout << "! ";
for (int i = 1; i <= n; i ++) cout << dans[i] << ' '; cout << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3528kb
input:
3 0 0 1
output:
? 1 2 ? 1 3 ? 2 3 ! 0 3 1
result:
wrong output format Unexpected end of file - token expected