QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#107851 | #6303. Inversion | LG_Monkey | WA | 322ms | 3420kb | C++14 | 1.3kb | 2023-05-22 22:43:13 | 2023-05-22 22:43:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define deb(var) cerr << #var << '=' << var << "; "
//#define int long long
int n, a[100010], i, p[20001];
struct BIT {
int w[2010];
void add(int p, int x) {
for (int i = p; i <= 2000; i += i & (-i)) w[i] += x;
}
int query(int p) {
int res = 0;
for (int i = p; i; i -= i & (-i)) res += w[i];
return res;
}
} bit;
int q(int l, int r) {
if (l >= r) return 0;
if (r < i) {
memset(bit.w, 0, sizeof bit.w);
int ans = 0;
for (int j = 1; j <= i; j++) {
if (a[j] >= l && a[j] <= r) {
ans += bit.query(2000) - bit.query(a[j]); bit.add(a[j], 1);
}
}
return ans;
}
cout << "? " << l << " " << r << endl;
int x; cin >> x; return x;
}
int cmp(int x, int y) {
return q(x, y) ^ q(x + 1, y) ^ q(x, y - 1) ^ q(x + 1, y - 1);
}
signed main() {
cin >> n;
i = 1; a[1] = 1;
for (i = 2; i <= n; i++) {
int l = 0, r = i - 1;
a[i] = i;
while (l < r) {
int mid = (l + r + 1) >> 1;
if (!cmp(a[mid], i)) l = mid; else r = mid - 1;
}
for (int j = i; j > l + 1; j--) a[j] = a[j - 1]; a[l + 1] = i;
}
for (int i = 1; i <= n; i++) p[a[i]] = i;
cout << "! ";
for (int i = 1; i <= n; i++) cout << p[i] << " "; cout << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3348kb
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: 322ms
memory: 3420kb
input:
1993 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 1 1 1 1 1 0 0 0 1 0 0 0 0 1 1 1 0 1 1 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 1 1 1 1 0 1 1 0 0 1 1 0 0 1 0 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 0 1 0 0 0 1 1 0 1 0 0 0 0 0 1 0 0 0 1 0 1...
output:
? 1 2 ? 1 3 ? 2 3 ? 2 3 ? 2 4 ? 3 4 ? 3 4 ? 2 5 ? 3 5 ? 1 5 ? 2 5 ? 2 6 ? 3 6 ? 5 6 ? 1 6 ? 2 6 ? 1 7 ? 2 7 ? 5 7 ? 6 7 ? 1 8 ? 2 8 ? 5 8 ? 6 8 ? 7 8 ? 6 9 ? 7 9 ? 8 9 ? 7 9 ? 8 9 ? 6 10 ? 7 10 ? 9 10 ? 7 10 ? 8 10 ? 5 11 ? 6 11 ? 10 11 ? 9 11 ? 10 11 ? 5 12 ? 6 12 ? 11 12 ? 9 12 ? 10 12 ? 8 13 ? 9 ...
result:
wrong answer Wa.