CSES - Datatähti 2025 loppu - Results
Submission details
Task:Poistot
Sender:Pikaksi
Submission time:2025-01-18 14:02:51 +0200
Language:C++ (C++20)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.00 s1, 3details
#20.00 s1, 2, 3details
#30.00 s1, 3details
#40.00 s1, 3details
#50.01 s2, 3details
#60.01 s2, 3details
#70.01 s3details
#80.01 s3details
#90.01 s3details
#100.01 s3details

Compiler report

input/code.cpp: In function 'void solve()':
input/code.cpp:70:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for (int i = 0; i < ans.size(); i++) {
      |                     ~~^~~~~~~~~~~~

Code

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
// chmod u+x b.sh
void solve(); int main() {
    ios_base::sync_with_stdio(0); cout.tie(0);
    solve();
}

const int N = 1 << 5;

pair<int, int> seg[N * 2];

void segset(int val, int loc)
{
    seg[loc + N] = {val, -loc};
    loc += N;
    for (loc /= 2; loc >= 1; loc /= 2) {
        seg[loc] = max(seg[loc * 2], seg[loc * 2 + 1]);
    }
}

pair<int, int> segget(int l, int r)
{
    pair<int, int> ans = {0, 0};
    l += N;
    r += N;
    while (l <= r) {
        if (l % 2 == 1) ans = max(ans, seg[l++]);
        if (r % 2 == 0) ans = max(ans, seg[r--]);
        l /= 2;
        r /= 2;
    }
    ans.second *= -1;
    return ans;
}

void solve()
{
    int n;
    cin >> n;
    vector<int> vals;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        vals.push_back(a);
        segset(a, i);
    }
    int remain = n;
    vector<vector<int>> ans;
    while (remain > 0) {
        //cout << "removing" << endl;
        int r = n - 1;
        vector<int> remove;
        while (r >= 0) {
            auto [val, loc] = segget(0, r);
            //cout << "loop " << val << " " << loc << endl;
            if (val == 0) break;
            segset(0, loc);
            remove.push_back(val);
            r = loc - 1;
            remain--;
        }
        if (remove.size() == 0) break;
        ans.push_back(remove);
    }
    cout << ans.size() << "\n";
    for (int i = 0; i < ans.size(); i++) {
        for (int k = ans[i].size() - 1; k >= 0; k--) cout << ans[i][k] << " ";
        cout << "\n";
    }
}

Test details

Test 1

Group: 1, 3

Verdict:

input
1000
447773962 773442532 122816 137...

correct output
53
447773962 773442532 908719430 ...

user output
(empty)

Error:
malloc(): unaligned tcache chunk detected

Test 2

Group: 1, 2, 3

Verdict:

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

correct output
1000




...

user output
(empty)

Error:
malloc(): unaligned tcache chunk detected

Test 3

Group: 1, 3

Verdict:

input
1000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
1
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)

Error:
malloc(): unaligned tcache chunk detected

Test 4

Group: 1, 3

Verdict:

input
1000
1000 999 998 997 996 995 994 9...

correct output
1000
1000 
999 
998 
997 
...

user output
(empty)

Error:
malloc(): unaligned tcache chunk detected

Test 5

Group: 2, 3

Verdict:

input
200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
200000




...

user output
(empty)

Error:
malloc(): corrupted top size

Test 6

Group: 2, 3

Verdict:

input
200000
5 2 1 10 6 10 5 5 5 4 4 2 3 7 ...

correct output
20776
5 10 
2 6 10 
1 5 7 9 10 
5 7 8 9 10 
...

user output
(empty)

Error:
malloc(): corrupted top size

Test 7

Group: 3

Verdict:

input
200000
591414747 75940263 760367935 9...

correct output
879
591414747 760367935 901888417 ...

user output
(empty)

Error:
malloc(): corrupted top size

Test 8

Group: 3

Verdict:

input
200000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
1
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)

Error:
malloc(): corrupted top size

Test 9

Group: 3

Verdict:

input
200000
200000 199999 199998 199997 19...

correct output
200000
200000 
199999 
199998 
199997 
...

user output
(empty)

Error:
malloc(): corrupted top size

Test 10

Group: 3

Verdict:

input
200000
199999 199997 199995 199993 19...

correct output
100000
199999 200000 
199997 199998 
199995 199996 
199993 199994 
...

user output
(empty)

Error:
malloc(): corrupted top size