QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627710#9249. Elimination Series Once Morenjupt_zy#WA 1ms3884kbC++202.4kb2024-10-10 16:50:512024-10-10 16:50:52

Judging History

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

  • [2024-10-10 16:50:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3884kb
  • [2024-10-10 16:50:51]
  • 提交

answer

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

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

constexpr int M = 10, 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 = a[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: 0ms
memory: 3680kb

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: 0ms
memory: 3664kb

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: 0
Accepted
time: 0ms
memory: 3680kb

input:

3 0
1 2 7 4 5 8 3 6

output:

0 1 2 0 0 3 0 1

result:

ok 8 numbers

Test #4:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

3 5
3 7 1 2 4 8 5 6

output:

1 2 0 1 2 3 2 2

result:

ok 8 numbers

Test #5:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

3 3
3 4 8 2 7 6 1 5

output:

1 2 3 1 2 2 0 2

result:

ok 8 numbers

Test #6:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

3 3
4 2 6 8 3 5 1 7

output:

2 1 2 3 1 2 0 2

result:

ok 8 numbers

Test #7:

score: 0
Accepted
time: 0ms
memory: 3724kb

input:

3 4
5 8 1 3 2 4 6 7

output:

2 3 0 1 1 2 2 2

result:

ok 8 numbers

Test #8:

score: 0
Accepted
time: 0ms
memory: 3700kb

input:

3 1
7 3 8 6 5 2 4 1

output:

2 1 3 1 2 1 2 0

result:

ok 8 numbers

Test #9:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

3 4
1 2 5 3 6 7 4 8

output:

0 1 2 1 2 2 2 3

result:

ok 8 numbers

Test #10:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

3 2
2 4 8 6 3 7 5 1

output:

1 2 3 2 1 2 2 0

result:

ok 8 numbers

Test #11:

score: -100
Wrong Answer
time: 1ms
memory: 3884kb

input:

10 780
495 929 348 345 426 543 187 419 839 812 320 1018 251 284 944 258 721 640 730 528 316 247 313 195 809 948 261 615 805 213 388 894 1005 77 599 636 881 444 144 923 240 520 592 465 96 455 563 943 237 860 531 269 106 989 740 506 23 224 84 475 108 718 3 16 731 436 591 627 672 300 573 613 253 637 46...

output:

8 10 8 8 8 10 7 8 10 10 8 10 7 8 10 8 10 10 10 10 8 7 8 7 10 10 8 10 10 7 8 10 10 6 10 10 10 8 7 10 7 10 10 8 6 8 10 10 7 10 10 8 6 10 10 8 4 7 6 8 6 10 1 4 10 8 10 10 10 8 10 10 7 10 8 10 10 10 6 7 6 7 10 10 10 10 10 7 6 8 8 8 10 10 6 6 10 10 10 8 10 10 6 10 10 8 6 7 8 8 3 8 8 10 6 10 7 8 8 10 10 1...

result:

wrong answer 2nd numbers differ - expected: '9', found: '10'