QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627693#9249. Elimination Series Once Morenjupt_zy#WA 2ms11864kbC++202.3kb2024-10-10 16:46:422024-10-10 16:46:43

Judging History

你现在查看的是最新测评结果

  • [2024-10-10 16:46:43]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11864kb
  • [2024-10-10 16:46:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;

constexpr int M = 20, N = (1 << M) + 10;
int a[N], rt[N], cnt[30 * N], ls[30 * N], rs[30 * N], rtl[(1 << (M + 1)) + 10], rtr[(1 << (M + 1)) + 10], b[N], fa[N][M][2];
int n, k, idx;

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) / 2;
    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) {
    cnt[q = ++idx] = cnt[p];
    ls[q] = ls[p];
    rs[q] = rs[p];

    if (l == r) {
        cnt[q] += v;
        return;
    }

    int m = l + r >> 1;
    if (x <= m) {
        add(ls[p], ls[q], l, m, x, v);
    } else {
        add(rs[p], rs[q], m + 1, r, x, v);
    }
    cnt[q] = cnt[ls[q]] + cnt[rs[q]];
}

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 cnt[q] - cnt[p];
    }

    int m = l + r >> 1;
    return query(ls[p], ls[q], l, m, x, y) + query(rs[p], rs[q], m + 1, r, x, y);
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> k;

    for (int i = 1; i <= (1 << n); i++) {
        cin >> a[i];
        add(rt[i - 1], rt[i], 1, (1 << n), a[i], 1);
    }   

    build(1, 1, (1 << n));

    for (int i = 1; i <= (1 << n); i++) {
        int t = b[i], cnt = 0;
        while (t) {
            fa[i][cnt][0] = rtl[t];
            fa[i][cnt++][1] = rtr[t];
            t /= 2;
        }
    }

    for (int i = 1; i <= (1 << n); i++) {
        int lo = 0, hi = n;
        auto check = [&](int x) -> bool {
            int l = fa[i][x][0], r = fa[i][x][1], cnt = query(rt[l - 1], rt[r], 1, (1 << n), a[i] + 1, (1 << n));
            int len = r - l + 1, has = i - 1, use = len - cnt - 1;
            has -= use;
            if (cnt <= k && has >= cnt) {
                return true;
            }
            return false;
        };

        while (lo < hi) {
            int m = (lo + hi + 1) / 2;
            if (check(m)) {
                lo = m;
            } else {
                hi = m - 1;
            }
        }
        cout << lo << " \n"[i == (1 << n)];
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11784kb

input:

2 1
1 2 3 4

output:

0 1 1 2

result:

ok 4 number(s): "0 1 1 2"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 11864kb

input:

3 5
2 4 7 5 3 8 6 1

output:

0 1 1 2 2 2 2 2

result:

wrong answer 1st numbers differ - expected: '1', found: '0'