QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#628231 | #9249. Elimination Series Once More | njupt_zy# | WA | 2ms | 9856kb | C++23 | 2.3kb | 2024-10-10 19:13:01 | 2024-10-10 19:13:02 |
Judging History
answer
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;
constexpr int M = 21, N = (1 << (M - 1)) + 9;
struct Node {
int l, r;
int cnt;
} tr[21 * N];
int a[N], rt[N], rtl[(1 << (M + 1)) + 10], rtr[(1 << (M + 1)) + 10], b[N];
int n, k, idx;
inline int read() {
int x = 0; char c = getchar(), fs = 0; while(! isdigit(c)) fs |= (c == '-'), c = getchar();
while(isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return fs ? -x : x;
}
void build(int p, int l, int r) {
rtl[p] = l, rtr[p] = r;
if (l == r) {
b[l] = p;
return;
}
int m = (l + r) >> 1;
build(2 * p, l, m);
build(2 * p + 1, m + 1, r);
}
void add(int p, int &q, int l, int r, int x, int v) {
tr[q] = tr[p];
if (l == r) {
tr[q].cnt += v;
return;
}
int m = l + r >> 1;
if (x <= m) {
add(tr[p].l, tr[q].l, l, m, x, v);
} else {
add(tr[p].r, tr[q].r, m + 1, r, x, v);
}
tr[q].cnt = tr[tr[q].l].cnt + tr[tr[q].r].cnt;
}
int query(int p, int q, int l, int r, int x, int y) {
if (l > y || r < x) {
return 0;
}
if (l >= x && r <= y) {
return tr[q].cnt - tr[p].cnt;
}
int m = l + r >> 1;
return query(tr[p].l, tr[q].l, l, m, x, y) + query(tr[p].r, tr[q].r, m + 1, r, x, y);
}
bool check(int i, int x) {
int now = b[i] / (1 << x);
int l = rtl[now], r = rtr[now], cnt = query(rt[l - 1], rt[r], 1, (1 << n), a[i] + 1, (1 << n));
int len = r - l + 1, has = a[i] - 1, use = len - cnt - 1;
has -= use;
if (cnt <= k && has >= cnt) {
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
n = read(), k = read();
const int m = (1 << n);
for (int i = 1; i <= m; i++) {
a[i] = read();
add(rt[i - 1], rt[i], 1, m, a[i], 1);
}
build(1, 1, m);
for (int i = 1; i <= m; i++) {
int lo = 0, hi = n;
while (lo < hi) {
int m = (lo + hi + 1) / 2;
if (check(i, m)) {
lo = m;
} else {
hi = m - 1;
}
}
cout << lo << " \n"[i == m];
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9804kb
input:
2 1 1 2 3 4
output:
0 1 1 2
result:
ok 4 number(s): "0 1 1 2"
Test #2:
score: 0
Accepted
time: 2ms
memory: 9856kb
input:
3 5 2 4 7 5 3 8 6 1
output:
1 2 2 2 1 3 2 0
result:
ok 8 numbers
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 9740kb
input:
3 0 1 2 7 4 5 8 3 6
output:
0 1 2 2 2 3 1 2
result:
wrong answer 4th numbers differ - expected: '0', found: '2'