QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#628530#9249. Elimination Series Once MorelongyinWA 5ms23232kbC++201.6kb2024-10-10 20:48:302024-10-10 20:48:30

Judging History

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

  • [2024-10-10 20:48:30]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:23232kb
  • [2024-10-10 20:48:30]
  • 提交

answer

#include <bits/stdc++.h>
//#define int long long
#define endl "\n"
using namespace std;

using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int N = 2e6 + 5;

struct BIT {
    ll tr[N];
    int n;
    BIT(int n = N - 1) : n(n) {
        memset(tr, 0, sizeof tr);
    }
    int lowbit(int x) {
        return x & -x;
    }
    void add(int x, int k) {
        for (int i = x; i <= n; i += lowbit(i)) {
            tr[i] += k;
        }
    }
    ll sum(int x) {
        ll res = 0;
        for (int i = x; i >= 1; i -= lowbit(i)) {
            res += tr[i];
        }
        return res;
    }
    ll sum(int l, int r) {
        return sum(r) - sum(l - 1);
    }
} bit;

pair<int, int> a[N];
int ans[N];

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

    int n, k;
    cin >> n >> k;
    set<int> sp;
    for (int i = 1; i <= n; i++) {
        sp.insert(1 << i);
    }
    n = (1 << n);
    for (int i = 1; i <= n; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a, a + n + 1);

    for (int i = 1; i <= n; i++) {
        auto& [x, id] = a[i];
        int l = id % 2 ? id : id - 1, r = id % 2 ? id + 1 : id;
        while (l >= 1 && r <= n && bit.sum(l, r) >= (r - l - k) && (r - l) < x) {
            ans[id]++;
            if (!sp.count(r) || l == 1)
                r = 2 * r - l + 1;
            else 
                l = 2 * l - r - 1;
        }
        bit.add(id, 1);
    }
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << " ";
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 21480kb

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: 21896kb

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: 2ms
memory: 22044kb

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: 21764kb

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: 4ms
memory: 23020kb

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: 2ms
memory: 23104kb

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: 5ms
memory: 22240kb

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: 5ms
memory: 21780kb

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: 2ms
memory: 22440kb

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: 23232kb

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

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 9 8 8 8 9 7 8 9 9 8 9 7 8 9 8 9 9 9 9 8 7 8 7 9 9 8 9 9 7 8 9 9 6 9 9 9 8 7 9 7 9 9 8 6 8 9 9 7 9 9 8 6 9 9 8 4 7 6 8 6 9 1 4 9 8 9 9 9 8 9 9 7 9 8 9 9 9 6 7 6 7 9 9 9 9 9 7 6 8 8 8 9 9 6 6 9 9 9 8 9 9 6 9 9 8 6 7 8 8 3 8 8 9 6 9 7 8 8 9 9 9 9 8 7 9 8 8 7 7 9 9 9 9 9 8 8 9 6 9 9 9 9 9 9 6 9 8 8 9 ...

result:

wrong answer 515th numbers differ - expected: '9', found: '8'