QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#594474 | #6303. Inversion | shiqiaqiaya | WA | 51ms | 66280kb | C++20 | 2.2kb | 2024-09-28 00:28:30 | 2024-09-28 00:28:30 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
template <class T, class ... A> void debug(const T & t, const A & ... a) {
cerr << "[" << t, ((cerr << ", " << a), ...), cerr << "]\n";
}
mt19937 rnd(time(0));
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// int t = 0;
// for (int i = 1; i < 2000; i++) {
// t += log2(i) * 2;
// }
// cout << t << "\n";
int n;
cin >> n;
vector<int> a;
a.push_back(1);
vector vis(n + 1, vector<int> (n + 1, -1));
auto ask = [&](int l, int r) -> int {
if (l >= r) return 0;
if (vis[l][r] != -1) return vis[l][r];
cout << "? " << l << " " << r << endl;
int x;
cin >> x;
return vis[l][r] = x;
};
vector dp(n + 1, vector<int> (n + 1, 0));
auto compare = [&](int x, int y, int a, int d) -> bool {
// int a = ask(x, y - 1);
int b = ask(x + 1, y);
int c = ask(x, y);
// int d = ask(x + 1, y - 1);
if ((a + b + c - d + 2) % 2 == 0) return false;
return true;
};
for (int i = 2; i <= n; i++) {
int L = 0, R = a.size() - 1, res = -1;
while (L <= R) {
int mid = (L + R) / 2;
int x0 = dp[a[mid]][i - 1], x1 = dp[a[mid] + 1][i - 1];
if (!compare(a[mid], i, x0, x1)) {
res = mid;
L = mid + 1;
} else {
R = mid - 1;
}
}
a.insert(a.begin() + res + 1, i);
vector<int> d(i + 1);
for (int j = 0; j < a.size(); j++) {
if (j == res + 1) continue;
if (j < res + 1) {
d[a[j]] = 0;
} else {
d[a[j]] = 1;
}
}
for (int j = 1; j < i; j++) {
d[j] += d[j - 1];
dp[j][i] = dp[j][i - 1] + d[j];
}
}
vector<int> ans(n + 1);
for (int i = 0; i < n; i++) {
ans[a[i]] = i + 1;
}
cout << "! ";
for (int i = 1; i <= n; i++) {
cout << ans[i] << " \n"[i == n];
}
// for (int i = 0; i < a.size(); i++) {
// cout << a[i] << " \n"[i == a.size() - 1];
// }
// for (int i = 1; i <= n; i++) {
// for (int j = 1; j <= n; j++) {
// cout << dp[i][j] << " \n"[j == n];
// }
// }
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3888kb
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: 51ms
memory: 66280kb
input:
1993 0 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 1 0 1 1 1 0 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 0 1 1 1 1 1 0 0 1 0 0 1 1 1 1 0 1 1 0 1 0 0 0 0 0 1 0 0 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 1 0 1 0 1 0 1 1 1 0 1 0 0 1 1 0 1 0 1 0 1 1 0 0 1 0 1 0 1 0 1 0...
output:
? 1 2 ? 2 3 ? 1 3 ? 3 4 ? 2 4 ? 3 5 ? 2 5 ? 1 5 ? 3 6 ? 2 6 ? 5 6 ? 1 6 ? 2 7 ? 1 7 ? 6 7 ? 5 7 ? 2 8 ? 1 8 ? 4 8 ? 3 8 ? 2 9 ? 1 9 ? 8 9 ? 3 9 ? 3 10 ? 2 10 ? 9 10 ? 8 10 ? 3 11 ? 2 11 ? 9 11 ? 8 11 ? 10 11 ? 11 12 ? 10 12 ? 7 12 ? 6 12 ? 2 12 ? 1 12 ? 3 13 ? 2 13 ? 12 13 ? 11 13 ? 4 13 ? 5 13 ? 11...
result:
wrong answer Wa.