Submission #152813

# Submission time Handle Problem Language Result Execution time Memory
152813 2019-09-09T16:07:31 Z theboatman Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1375 ms 68472 KB
#include <bits/stdc++.h>

#define y1 theboatman
#define make_struct(args...) {args}

using namespace std;

struct tree {
    int v, tl, tr;
    vector <int> t;

    void init(int n) {
        t.resize(n * 8);

        v = 1;
        tl = 0, tr = n - 1;
    }

    void modify(int v, int tl, int tr, int pos, int val) {
        if (tl == tr) {
            t[v] = max(t[v], val);
        }
        else {
            int tm = (tl + tr) / 2;
            if (pos <= tm) {
                modify(v * 2, tl, tm, pos, val);
            }
            else {
                modify(v * 2 + 1, tm + 1, tr, pos, val);
            }

            t[v] = max(t[v * 2], t[v * 2 + 1]);
        }
    }

    void modify(int pos, int val) {
        modify(v, tl, tr, pos, val);
    }

    int get(int v, int tl, int tr, int l, int r) {
        if (l > r) {
            return 0;
        }

        if (tl == l && tr == r) {
            return t[v];
        }

        int tm = (tl + tr) / 2;
        int ql = get(v * 2, tl, tm, l, min(r, tm));
        int qr = get(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r);

        return max(ql, qr);
    }

    int get_suff(int l) {
        return get(v, tl, tr, l, tr);
    }
};

struct Query {
    int l, r, k, ind;
};

bool cmpQuery(Query a, Query b) {
    return a.r < b.r;
}

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

    int n, m;
    cin >> n >> m;

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

    vector <Query> b(m);
    for(int i = 0; i < m; i++) {
        cin >> b[i].l >> b[i].r >> b[i].k;
        b[i].l--, b[i].r--;

        b[i].ind = i;
    }

    sort(b.begin(), b.end(), cmpQuery);

    tree t;
    t.init(n);

    int r = 0;
    vector <int> stak, ans(m);

    for(int i = 0; i < n; i++) {
        while(stak.size() && a[stak.back()] <= a[i]) {
            stak.pop_back();
        }

        if (stak.size()) {
            int l = stak.back();
            int x = a[l] + a[i];

            while(r < m && b[r].r < i) {
                ans[b[r].ind] = max(ans[b[r].ind], t.get_suff(b[r].l));
                r++;
            }
            t.modify(l, x);
        }

        stak.push_back(i);
    }

    for(int i = r; i < m; i++) {
        ans[b[i].ind] = max(ans[b[i].ind], t.get_suff(b[i].l));
    }

    for(int i = 0; i < m; i++) {
        ans[b[i].ind] = (ans[b[i].ind] <= b[i].k);
    }

    for(int i = 0; i < m; i++) {
        cout << ans[i] << "\n";
    }
    return 0;
}
/*
*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 6 ms 632 KB Output is correct
13 Correct 6 ms 632 KB Output is correct
14 Correct 7 ms 760 KB Output is correct
15 Correct 7 ms 760 KB Output is correct
16 Correct 6 ms 760 KB Output is correct
17 Correct 5 ms 760 KB Output is correct
18 Correct 6 ms 732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1374 ms 57080 KB Output is correct
2 Correct 1360 ms 67548 KB Output is correct
3 Correct 1354 ms 66932 KB Output is correct
4 Correct 1363 ms 67508 KB Output is correct
5 Correct 1122 ms 67492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 6008 KB Output is correct
2 Correct 103 ms 8028 KB Output is correct
3 Correct 85 ms 8184 KB Output is correct
4 Correct 86 ms 8072 KB Output is correct
5 Correct 86 ms 8056 KB Output is correct
6 Correct 78 ms 7800 KB Output is correct
7 Correct 78 ms 7928 KB Output is correct
8 Correct 86 ms 7644 KB Output is correct
9 Correct 51 ms 3832 KB Output is correct
10 Correct 82 ms 7672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 6 ms 632 KB Output is correct
13 Correct 6 ms 632 KB Output is correct
14 Correct 7 ms 760 KB Output is correct
15 Correct 7 ms 760 KB Output is correct
16 Correct 6 ms 760 KB Output is correct
17 Correct 5 ms 760 KB Output is correct
18 Correct 6 ms 732 KB Output is correct
19 Correct 249 ms 18288 KB Output is correct
20 Correct 248 ms 18296 KB Output is correct
21 Correct 227 ms 18168 KB Output is correct
22 Correct 231 ms 18168 KB Output is correct
23 Correct 232 ms 18176 KB Output is correct
24 Correct 185 ms 18044 KB Output is correct
25 Correct 187 ms 17992 KB Output is correct
26 Correct 195 ms 18252 KB Output is correct
27 Correct 198 ms 18248 KB Output is correct
28 Correct 200 ms 18296 KB Output is correct
29 Correct 206 ms 18336 KB Output is correct
30 Correct 209 ms 18296 KB Output is correct
31 Correct 207 ms 18424 KB Output is correct
32 Correct 210 ms 18296 KB Output is correct
33 Correct 203 ms 18300 KB Output is correct
34 Correct 179 ms 17912 KB Output is correct
35 Correct 177 ms 17912 KB Output is correct
36 Correct 177 ms 17940 KB Output is correct
37 Correct 190 ms 17772 KB Output is correct
38 Correct 177 ms 17912 KB Output is correct
39 Correct 197 ms 16908 KB Output is correct
40 Correct 152 ms 13944 KB Output is correct
41 Correct 183 ms 16460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 6 ms 632 KB Output is correct
13 Correct 6 ms 632 KB Output is correct
14 Correct 7 ms 760 KB Output is correct
15 Correct 7 ms 760 KB Output is correct
16 Correct 6 ms 760 KB Output is correct
17 Correct 5 ms 760 KB Output is correct
18 Correct 6 ms 732 KB Output is correct
19 Correct 1374 ms 57080 KB Output is correct
20 Correct 1360 ms 67548 KB Output is correct
21 Correct 1354 ms 66932 KB Output is correct
22 Correct 1363 ms 67508 KB Output is correct
23 Correct 1122 ms 67492 KB Output is correct
24 Correct 105 ms 6008 KB Output is correct
25 Correct 103 ms 8028 KB Output is correct
26 Correct 85 ms 8184 KB Output is correct
27 Correct 86 ms 8072 KB Output is correct
28 Correct 86 ms 8056 KB Output is correct
29 Correct 78 ms 7800 KB Output is correct
30 Correct 78 ms 7928 KB Output is correct
31 Correct 86 ms 7644 KB Output is correct
32 Correct 51 ms 3832 KB Output is correct
33 Correct 82 ms 7672 KB Output is correct
34 Correct 249 ms 18288 KB Output is correct
35 Correct 248 ms 18296 KB Output is correct
36 Correct 227 ms 18168 KB Output is correct
37 Correct 231 ms 18168 KB Output is correct
38 Correct 232 ms 18176 KB Output is correct
39 Correct 185 ms 18044 KB Output is correct
40 Correct 187 ms 17992 KB Output is correct
41 Correct 195 ms 18252 KB Output is correct
42 Correct 198 ms 18248 KB Output is correct
43 Correct 200 ms 18296 KB Output is correct
44 Correct 206 ms 18336 KB Output is correct
45 Correct 209 ms 18296 KB Output is correct
46 Correct 207 ms 18424 KB Output is correct
47 Correct 210 ms 18296 KB Output is correct
48 Correct 203 ms 18300 KB Output is correct
49 Correct 179 ms 17912 KB Output is correct
50 Correct 177 ms 17912 KB Output is correct
51 Correct 177 ms 17940 KB Output is correct
52 Correct 190 ms 17772 KB Output is correct
53 Correct 177 ms 17912 KB Output is correct
54 Correct 197 ms 16908 KB Output is correct
55 Correct 152 ms 13944 KB Output is correct
56 Correct 183 ms 16460 KB Output is correct
57 Correct 1373 ms 68384 KB Output is correct
58 Correct 1353 ms 68444 KB Output is correct
59 Correct 1375 ms 68472 KB Output is correct
60 Correct 1363 ms 68276 KB Output is correct
61 Correct 1321 ms 65056 KB Output is correct
62 Correct 1341 ms 68260 KB Output is correct
63 Correct 979 ms 64068 KB Output is correct
64 Correct 988 ms 63992 KB Output is correct
65 Correct 1116 ms 64392 KB Output is correct
66 Correct 1096 ms 66576 KB Output is correct
67 Correct 1101 ms 67076 KB Output is correct
68 Correct 1202 ms 65316 KB Output is correct
69 Correct 1137 ms 64952 KB Output is correct
70 Correct 1139 ms 68388 KB Output is correct
71 Correct 1117 ms 68100 KB Output is correct
72 Correct 1128 ms 67648 KB Output is correct
73 Correct 951 ms 63772 KB Output is correct
74 Correct 942 ms 65452 KB Output is correct
75 Correct 941 ms 64036 KB Output is correct
76 Correct 944 ms 65736 KB Output is correct
77 Correct 935 ms 64016 KB Output is correct
78 Correct 1060 ms 63352 KB Output is correct
79 Correct 791 ms 46760 KB Output is correct
80 Correct 1041 ms 65096 KB Output is correct