Submission details
Task:Lisäykset
Sender:ollpu
Submission time:2025-11-29 10:19:16 +0200
Language:C++ (C++20)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED20
#2ACCEPTED33
#3ACCEPTED47
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3details
#2ACCEPTED0.00 s1, 2, 3details
#3ACCEPTED0.00 s1, 3details
#4ACCEPTED0.00 s1, 3details
#5ACCEPTED0.00 s1, 3details
#6ACCEPTED0.03 s2, 3details
#7ACCEPTED0.04 s3details
#8ACCEPTED0.04 s3details
#9ACCEPTED0.04 s3details
#10ACCEPTED0.12 s3details
#11ACCEPTED0.12 s3details

Code

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    map<int, pair<int, int>> p;
    int lst = -1;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (x != lst) p[i] = {x, 0};
        lst = x;
    }
    p[n] = {1e9, 0};
    auto mergeck = [&](auto it1) {
        auto it2 = next(it1);
        if (it1->second.first + it1->second.second == it2->second.first) {
            it1->second.second += it2->second.second;
            p.erase(it2);
        }
    };
    auto print = [&]() {
        lst = n;
        int add = 0;
        int res[n];
        for (auto [pos, d] : views::reverse(p)) {
            add += d.second;
            for (int i = pos; i < lst; ++i) res[i] = d.first + add;
            lst = pos;
        }
        for (int i = 0; i < n; ++i) cout << res[i] << " ";
        cout << endl;
    };
    for (int i = 0; i < m; ++i) {
        int k;
        cin >> k;
        if (!k) continue;
        k--;
        auto it2 = p.upper_bound(k);
        auto it1 = prev(it2);
        if (it2->first != k+1) {
            int amt = k-it1->first+1;
            assert(amt > 0);
            int pos = it2->first - amt;
            assert(pos != it1->first);
            auto cp = it1->second;
            auto ins = p.insert(it2, {pos, {cp.first+cp.second+1, 0}});
            mergeck(ins);
            if (it1 == p.begin()) continue;
            it1 = prev(it1);
        }
        it1->second.second++;
        mergeck(it1);
    }
    print();
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
1 1000
0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1000 

user output
1000 

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
1000 1000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
511 511 511 511 511 511 511 51...

user output
511 511 511 511 511 511 511 51...

Test 3

Group: 1, 3

Verdict: ACCEPTED

input
1000 1000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
495 495 495 495 495 495 495 49...

user output
495 495 495 495 495 495 495 49...

Test 4

Group: 1, 3

Verdict: ACCEPTED

input
1000 1000
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 ...

correct output
562 562 562 562 562 562 562 56...

user output
562 562 562 562 562 562 562 56...

Test 5

Group: 1, 3

Verdict: ACCEPTED

input
1000 1000
0 1 3 4 6 9 9 9 10 11 11 11 11...

correct output
997 997 997 997 997 998 998 99...

user output
997 997 997 997 997 998 998 99...

Test 6

Group: 2, 3

Verdict: ACCEPTED

input
100000 100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
50033 50033 50033 50033 50033 ...

user output
50033 50033 50033 50033 50033 ...

Test 7

Group: 3

Verdict: ACCEPTED

input
100000 100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
49996 49996 49996 49996 49996 ...

user output
49996 49996 49996 49996 49996 ...

Test 8

Group: 3

Verdict: ACCEPTED

input
100000 100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
50057 50057 50057 50057 50057 ...

user output
50057 50057 50057 50057 50057 ...

Test 9

Group: 3

Verdict: ACCEPTED

input
100000 100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
50536 50536 50536 50536 50536 ...

user output
50536 50536 50536 50536 50536 ...

Test 10

Group: 3

Verdict: ACCEPTED

input
100000 100000
0 4 7 29 33 44 52 75 77 79 82 ...

correct output
100000 100001 100003 100023 10...

user output
100000 100001 100003 100023 10...

Test 11

Group: 3

Verdict: ACCEPTED

input
100000 100000
1 12 14 16 49 59 59 63 68 73 8...

correct output
100001 100010 100012 100014 10...

user output
100001 100010 100012 100014 10...