Submission #486988

# Submission time Handle Problem Language Result Execution time Memory
486988 2021-11-13T17:32:15 Z model_code Volontiranje (COCI21_volontiranje) C++17
110 / 110
266 ms 94440 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long llint;
typedef pair <int, int> pi;

const int MAXN = 1000005;

int n;
int p[MAXN];
vector <int> v[MAXN], r, st;
vector < vector <int> > out;

void build_LIS_struct () {
    for (int i = 1; i <= n; i++) {
        int pos = lower_bound(r.begin(), r.end(), p[i]) - r.begin();
        if (pos == r.size()) {
            r.push_back(p[i]);
        } else {
            r[pos] = p[i];
        }
        v[pos].push_back(i);
    }
    for (int i = 0; i < r.size(); i++) {
        reverse(v[i].begin(), v[i].end());
    }
}

void solve () {
    while (1) {
        if (st.size() == 0) {
            if (v[0].empty()) break;
            int pos = v[0].back();
            v[0].pop_back();
            st.push_back(pos);
        } else if (st.size() == r.size()) {
            out.push_back(st);
            st.clear();
        } else {
            int k = st.size();
            int curr = st.back();
            while (!v[k].empty() && v[k].back() < curr) v[k].pop_back();
            if (v[k].empty() || p[curr] > p[v[k].back()]) {
                st.pop_back();
            } else {
                int pos = v[k].back();
                v[k].pop_back();
                st.push_back(pos);
            }
        }
    }
}

void ispis () {
    cout << out.size() << " " << r.size() << endl;
    for (int i = 0; i < out.size(); i++) {
        for (auto x : out[i]) cout << x << " ";
        cout << '\n';
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    build_LIS_struct();
    solve();
    ispis();
    return 0;
}

Compilation message

Main.cpp: In function 'void build_LIS_struct()':
Main.cpp:18:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         if (pos == r.size()) {
      |             ~~~~^~~~~~~~~~~
Main.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i = 0; i < r.size(); i++) {
      |                     ~~^~~~~~~~~~
Main.cpp: In function 'void ispis()':
Main.cpp:57:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for (int i = 0; i < out.size(); i++) {
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 14 ms 23756 KB Output is correct
4 Correct 13 ms 23756 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 12 ms 23760 KB Output is correct
7 Correct 13 ms 23696 KB Output is correct
8 Correct 15 ms 23756 KB Output is correct
9 Correct 12 ms 23756 KB Output is correct
10 Correct 14 ms 23756 KB Output is correct
11 Correct 13 ms 23756 KB Output is correct
12 Correct 12 ms 23788 KB Output is correct
13 Correct 13 ms 23796 KB Output is correct
14 Correct 12 ms 23756 KB Output is correct
15 Correct 16 ms 23756 KB Output is correct
16 Correct 14 ms 23684 KB Output is correct
17 Correct 13 ms 23776 KB Output is correct
18 Correct 13 ms 23756 KB Output is correct
19 Correct 15 ms 23716 KB Output is correct
20 Correct 13 ms 23712 KB Output is correct
21 Correct 13 ms 23756 KB Output is correct
22 Correct 13 ms 23736 KB Output is correct
23 Correct 12 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 14 ms 23756 KB Output is correct
4 Correct 13 ms 23756 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 12 ms 23760 KB Output is correct
7 Correct 13 ms 23696 KB Output is correct
8 Correct 15 ms 23756 KB Output is correct
9 Correct 12 ms 23756 KB Output is correct
10 Correct 14 ms 23756 KB Output is correct
11 Correct 13 ms 23756 KB Output is correct
12 Correct 12 ms 23788 KB Output is correct
13 Correct 13 ms 23796 KB Output is correct
14 Correct 12 ms 23756 KB Output is correct
15 Correct 16 ms 23756 KB Output is correct
16 Correct 14 ms 23684 KB Output is correct
17 Correct 13 ms 23776 KB Output is correct
18 Correct 13 ms 23756 KB Output is correct
19 Correct 15 ms 23716 KB Output is correct
20 Correct 13 ms 23712 KB Output is correct
21 Correct 13 ms 23756 KB Output is correct
22 Correct 13 ms 23736 KB Output is correct
23 Correct 12 ms 23756 KB Output is correct
24 Correct 12 ms 23768 KB Output is correct
25 Correct 13 ms 23756 KB Output is correct
26 Correct 15 ms 23772 KB Output is correct
27 Correct 13 ms 23756 KB Output is correct
28 Correct 13 ms 23788 KB Output is correct
29 Correct 13 ms 23756 KB Output is correct
30 Correct 12 ms 23764 KB Output is correct
31 Correct 12 ms 23824 KB Output is correct
32 Correct 13 ms 23756 KB Output is correct
33 Correct 13 ms 23756 KB Output is correct
34 Correct 13 ms 23808 KB Output is correct
35 Correct 14 ms 23812 KB Output is correct
36 Correct 12 ms 23820 KB Output is correct
37 Correct 12 ms 23756 KB Output is correct
38 Correct 13 ms 23756 KB Output is correct
39 Correct 16 ms 23788 KB Output is correct
40 Correct 12 ms 23744 KB Output is correct
41 Correct 13 ms 23756 KB Output is correct
42 Correct 17 ms 23756 KB Output is correct
43 Correct 12 ms 23756 KB Output is correct
44 Correct 13 ms 23704 KB Output is correct
45 Correct 13 ms 23756 KB Output is correct
46 Correct 13 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 14 ms 23756 KB Output is correct
4 Correct 13 ms 23756 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 12 ms 23760 KB Output is correct
7 Correct 13 ms 23696 KB Output is correct
8 Correct 15 ms 23756 KB Output is correct
9 Correct 12 ms 23756 KB Output is correct
10 Correct 14 ms 23756 KB Output is correct
11 Correct 13 ms 23756 KB Output is correct
12 Correct 12 ms 23788 KB Output is correct
13 Correct 13 ms 23796 KB Output is correct
14 Correct 12 ms 23756 KB Output is correct
15 Correct 16 ms 23756 KB Output is correct
16 Correct 14 ms 23684 KB Output is correct
17 Correct 13 ms 23776 KB Output is correct
18 Correct 13 ms 23756 KB Output is correct
19 Correct 15 ms 23716 KB Output is correct
20 Correct 13 ms 23712 KB Output is correct
21 Correct 13 ms 23756 KB Output is correct
22 Correct 13 ms 23736 KB Output is correct
23 Correct 12 ms 23756 KB Output is correct
24 Correct 12 ms 23768 KB Output is correct
25 Correct 13 ms 23756 KB Output is correct
26 Correct 15 ms 23772 KB Output is correct
27 Correct 13 ms 23756 KB Output is correct
28 Correct 13 ms 23788 KB Output is correct
29 Correct 13 ms 23756 KB Output is correct
30 Correct 12 ms 23764 KB Output is correct
31 Correct 12 ms 23824 KB Output is correct
32 Correct 13 ms 23756 KB Output is correct
33 Correct 13 ms 23756 KB Output is correct
34 Correct 13 ms 23808 KB Output is correct
35 Correct 14 ms 23812 KB Output is correct
36 Correct 12 ms 23820 KB Output is correct
37 Correct 12 ms 23756 KB Output is correct
38 Correct 13 ms 23756 KB Output is correct
39 Correct 16 ms 23788 KB Output is correct
40 Correct 12 ms 23744 KB Output is correct
41 Correct 13 ms 23756 KB Output is correct
42 Correct 17 ms 23756 KB Output is correct
43 Correct 12 ms 23756 KB Output is correct
44 Correct 13 ms 23704 KB Output is correct
45 Correct 13 ms 23756 KB Output is correct
46 Correct 13 ms 23756 KB Output is correct
47 Correct 79 ms 27600 KB Output is correct
48 Correct 85 ms 27700 KB Output is correct
49 Correct 94 ms 29424 KB Output is correct
50 Correct 164 ms 33492 KB Output is correct
51 Correct 47 ms 26004 KB Output is correct
52 Correct 242 ms 77696 KB Output is correct
53 Correct 266 ms 94440 KB Output is correct
54 Correct 193 ms 42624 KB Output is correct
55 Correct 203 ms 42556 KB Output is correct
56 Correct 14 ms 23884 KB Output is correct
57 Correct 132 ms 31768 KB Output is correct
58 Correct 43 ms 25672 KB Output is correct
59 Correct 34 ms 25420 KB Output is correct
60 Correct 132 ms 31864 KB Output is correct
61 Correct 88 ms 28920 KB Output is correct
62 Correct 13 ms 23756 KB Output is correct
63 Correct 13 ms 23756 KB Output is correct
64 Correct 13 ms 23756 KB Output is correct
65 Correct 12 ms 23756 KB Output is correct
66 Correct 12 ms 23756 KB Output is correct
67 Correct 16 ms 23756 KB Output is correct
68 Correct 15 ms 23756 KB Output is correct
69 Correct 16 ms 23756 KB Output is correct