Submission #996372

# Submission time Handle Problem Language Result Execution time Memory
996372 2024-06-10T14:06:58 Z LOLOLO Volontiranje (COCI21_volontiranje) C++17
110 / 110
398 ms 143784 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (ll)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
ll mod = 1e9 + 7;
const int N = 1e6 + 1;
int st[N * 4];

void upd(int id, int l, int r, int p, int v) {
    st[id] = max(st[id], v);
    if (l == r) {
        return;
    }

    int m = (l + r) / 2;
    if (m >= p) {
        upd(id * 2, l, m, p, v);
    } else {
        upd(id * 2 + 1, m + 1, r, p, v);
    }
}

int get(int id, int l, int r, int u, int v) {
    if (l > v || r < u || u > v)
        return 0;

    if (l >= u && r <= v) {
        return st[id];
    }

    int m = (l + r) / 2;
    return max(get(id * 2, l, m, u, v), get(id * 2 + 1, m + 1, r, u, v));
}

int a[N], f[N], len = 0;
vector <int> layer[N], lst;

int dfs(int u) {
    lst.pb(u);

    if (f[u] == len) 
        return 1;

    while (sz(layer[f[u] + 1]) && layer[f[u] + 1].back() < u) {
        layer[f[u] + 1].pop_back();
    }

    while (sz(layer[f[u] + 1]) && a[layer[f[u] + 1].back()] > a[u]) {
        int is = dfs(layer[f[u] + 1].back());
        layer[f[u] + 1].pop_back();
        if (is) {
            return 1;
        }
    }

    lst.pop_back();
    return 0;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    for (int i = 1; i <= n; i++) {
        f[i] = get(1, 1, n, 1, a[i] - 1) + 1;
        upd(1, 1, n, a[i], f[i]);
        len = max(len, f[i]);
    } 

    for (int i = n; i >= 1; i--) {
        layer[f[i]].pb(i);
    }
    
    vector < vector <int>> ans;

    while (sz(layer[1])) {
        lst.clear();
        if (dfs(layer[1].back())) {
            ans.pb(lst);
        }

        layer[1].pop_back();
    }

    cout << sz(ans) << " " << len << '\n';
    for (auto x : ans) {
        for (auto t : x) {
            cout << t << ' ';
        }

        cout << '\n';
    }

    return 0;
}
 
# Verdict Execution time Memory Grader output
1 Correct 5 ms 27224 KB Output is correct
2 Correct 5 ms 27228 KB Output is correct
3 Correct 4 ms 27272 KB Output is correct
4 Correct 4 ms 27228 KB Output is correct
5 Correct 4 ms 27324 KB Output is correct
6 Correct 6 ms 27228 KB Output is correct
7 Correct 4 ms 27228 KB Output is correct
8 Correct 5 ms 27228 KB Output is correct
9 Correct 5 ms 27224 KB Output is correct
10 Correct 4 ms 27268 KB Output is correct
11 Correct 5 ms 27224 KB Output is correct
12 Correct 4 ms 27228 KB Output is correct
13 Correct 4 ms 27228 KB Output is correct
14 Correct 4 ms 27228 KB Output is correct
15 Correct 4 ms 27228 KB Output is correct
16 Correct 4 ms 27312 KB Output is correct
17 Correct 4 ms 27312 KB Output is correct
18 Correct 4 ms 27228 KB Output is correct
19 Correct 4 ms 27228 KB Output is correct
20 Correct 4 ms 27228 KB Output is correct
21 Correct 4 ms 27228 KB Output is correct
22 Correct 4 ms 27228 KB Output is correct
23 Correct 4 ms 27224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 27224 KB Output is correct
2 Correct 5 ms 27228 KB Output is correct
3 Correct 4 ms 27272 KB Output is correct
4 Correct 4 ms 27228 KB Output is correct
5 Correct 4 ms 27324 KB Output is correct
6 Correct 6 ms 27228 KB Output is correct
7 Correct 4 ms 27228 KB Output is correct
8 Correct 5 ms 27228 KB Output is correct
9 Correct 5 ms 27224 KB Output is correct
10 Correct 4 ms 27268 KB Output is correct
11 Correct 5 ms 27224 KB Output is correct
12 Correct 4 ms 27228 KB Output is correct
13 Correct 4 ms 27228 KB Output is correct
14 Correct 4 ms 27228 KB Output is correct
15 Correct 4 ms 27228 KB Output is correct
16 Correct 4 ms 27312 KB Output is correct
17 Correct 4 ms 27312 KB Output is correct
18 Correct 4 ms 27228 KB Output is correct
19 Correct 4 ms 27228 KB Output is correct
20 Correct 4 ms 27228 KB Output is correct
21 Correct 4 ms 27228 KB Output is correct
22 Correct 4 ms 27228 KB Output is correct
23 Correct 4 ms 27224 KB Output is correct
24 Correct 6 ms 27228 KB Output is correct
25 Correct 4 ms 27228 KB Output is correct
26 Correct 5 ms 27228 KB Output is correct
27 Correct 5 ms 27228 KB Output is correct
28 Correct 4 ms 27228 KB Output is correct
29 Correct 4 ms 27308 KB Output is correct
30 Correct 5 ms 27228 KB Output is correct
31 Correct 5 ms 27240 KB Output is correct
32 Correct 5 ms 27272 KB Output is correct
33 Correct 4 ms 27228 KB Output is correct
34 Correct 5 ms 27228 KB Output is correct
35 Correct 4 ms 27224 KB Output is correct
36 Correct 4 ms 27280 KB Output is correct
37 Correct 5 ms 27228 KB Output is correct
38 Correct 6 ms 27228 KB Output is correct
39 Correct 5 ms 27236 KB Output is correct
40 Correct 5 ms 27228 KB Output is correct
41 Correct 4 ms 27268 KB Output is correct
42 Correct 5 ms 27228 KB Output is correct
43 Correct 4 ms 27228 KB Output is correct
44 Correct 6 ms 27244 KB Output is correct
45 Correct 4 ms 27228 KB Output is correct
46 Correct 5 ms 27224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 27224 KB Output is correct
2 Correct 5 ms 27228 KB Output is correct
3 Correct 4 ms 27272 KB Output is correct
4 Correct 4 ms 27228 KB Output is correct
5 Correct 4 ms 27324 KB Output is correct
6 Correct 6 ms 27228 KB Output is correct
7 Correct 4 ms 27228 KB Output is correct
8 Correct 5 ms 27228 KB Output is correct
9 Correct 5 ms 27224 KB Output is correct
10 Correct 4 ms 27268 KB Output is correct
11 Correct 5 ms 27224 KB Output is correct
12 Correct 4 ms 27228 KB Output is correct
13 Correct 4 ms 27228 KB Output is correct
14 Correct 4 ms 27228 KB Output is correct
15 Correct 4 ms 27228 KB Output is correct
16 Correct 4 ms 27312 KB Output is correct
17 Correct 4 ms 27312 KB Output is correct
18 Correct 4 ms 27228 KB Output is correct
19 Correct 4 ms 27228 KB Output is correct
20 Correct 4 ms 27228 KB Output is correct
21 Correct 4 ms 27228 KB Output is correct
22 Correct 4 ms 27228 KB Output is correct
23 Correct 4 ms 27224 KB Output is correct
24 Correct 6 ms 27228 KB Output is correct
25 Correct 4 ms 27228 KB Output is correct
26 Correct 5 ms 27228 KB Output is correct
27 Correct 5 ms 27228 KB Output is correct
28 Correct 4 ms 27228 KB Output is correct
29 Correct 4 ms 27308 KB Output is correct
30 Correct 5 ms 27228 KB Output is correct
31 Correct 5 ms 27240 KB Output is correct
32 Correct 5 ms 27272 KB Output is correct
33 Correct 4 ms 27228 KB Output is correct
34 Correct 5 ms 27228 KB Output is correct
35 Correct 4 ms 27224 KB Output is correct
36 Correct 4 ms 27280 KB Output is correct
37 Correct 5 ms 27228 KB Output is correct
38 Correct 6 ms 27228 KB Output is correct
39 Correct 5 ms 27236 KB Output is correct
40 Correct 5 ms 27228 KB Output is correct
41 Correct 4 ms 27268 KB Output is correct
42 Correct 5 ms 27228 KB Output is correct
43 Correct 4 ms 27228 KB Output is correct
44 Correct 6 ms 27244 KB Output is correct
45 Correct 4 ms 27228 KB Output is correct
46 Correct 5 ms 27224 KB Output is correct
47 Correct 141 ms 40532 KB Output is correct
48 Correct 147 ms 40944 KB Output is correct
49 Correct 192 ms 46872 KB Output is correct
50 Correct 339 ms 52892 KB Output is correct
51 Correct 76 ms 32340 KB Output is correct
52 Correct 378 ms 143784 KB Output is correct
53 Correct 347 ms 113316 KB Output is correct
54 Correct 301 ms 61560 KB Output is correct
55 Correct 398 ms 61776 KB Output is correct
56 Correct 7 ms 27480 KB Output is correct
57 Correct 283 ms 49916 KB Output is correct
58 Correct 59 ms 31824 KB Output is correct
59 Correct 49 ms 31316 KB Output is correct
60 Correct 286 ms 50256 KB Output is correct
61 Correct 184 ms 42068 KB Output is correct
62 Correct 5 ms 27224 KB Output is correct
63 Correct 4 ms 27224 KB Output is correct
64 Correct 4 ms 27228 KB Output is correct
65 Correct 4 ms 27224 KB Output is correct
66 Correct 5 ms 27312 KB Output is correct
67 Correct 4 ms 27228 KB Output is correct
68 Correct 4 ms 27268 KB Output is correct
69 Correct 4 ms 27228 KB Output is correct