Submission #1061665

# Submission time Handle Problem Language Result Execution time Memory
1061665 2024-08-16T11:34:01 Z VMaksimoski008 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1674 ms 88408 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e6 + 5;

int tree[4*maxn+5];

void update(int u, int tl, int tr, int p, int v) {
    if(tl == tr) {
        tree[u] = max(tree[u], v);
    } else {
        int tm = (tl + tr) / 2;
        if(p <= tm) update(2*u, tl, tm, p, v);
        else update(2*u+1, tm+1, tr, p, v);
        tree[u] = max(tree[2*u], tree[2*u+1]);
    }
}

int query(int u, int tl, int tr, int l, int r) {
    if(l > tr || tl > r) return 0;
    if(l <= tl && tr <= r) return tree[u];
    int tm = (tl + tr) / 2;
    return max(query(2*u, tl, tm, l, r), query(2*u+1, tm+1, tr, l, r));
}

int main() {
    int n, q;
    cin >> n >> q;

    vector<int> v(n+1), ans(q);
    for(int i=1; i<=n; i++) cin >> v[i];

    vector<array<int, 3> > qus[n+1];
    for(int i=0; i<q; i++) {
        int l, r, k; cin >> l >> r >> k;
        qus[r].push_back({ l, k, i });
    }

    stack<int> st;
    for(int i=1; i<=n; i++) {
        while(!st.empty() && v[st.top()] <= v[i]) st.pop();
        if(!st.empty()) update(1, 1, n, st.top(), v[st.top()] + v[i]);
        for(auto &[l, k, id] : qus[i]) ans[id] = (query(1, 1, n, l, i) <= k);
        st.push(i);
    }

    for(int x : ans) cout << x << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 4 ms 600 KB Output is correct
13 Correct 4 ms 604 KB Output is correct
14 Correct 7 ms 600 KB Output is correct
15 Correct 6 ms 604 KB Output is correct
16 Correct 5 ms 604 KB Output is correct
17 Correct 4 ms 604 KB Output is correct
18 Correct 4 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1463 ms 63556 KB Output is correct
2 Correct 1492 ms 63652 KB Output is correct
3 Correct 1493 ms 63556 KB Output is correct
4 Correct 1482 ms 63568 KB Output is correct
5 Correct 1369 ms 55352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 6740 KB Output is correct
2 Correct 95 ms 6480 KB Output is correct
3 Correct 93 ms 5972 KB Output is correct
4 Correct 90 ms 7596 KB Output is correct
5 Correct 95 ms 7508 KB Output is correct
6 Correct 79 ms 7300 KB Output is correct
7 Correct 83 ms 7232 KB Output is correct
8 Correct 81 ms 7308 KB Output is correct
9 Correct 50 ms 3596 KB Output is correct
10 Correct 98 ms 7312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 4 ms 600 KB Output is correct
13 Correct 4 ms 604 KB Output is correct
14 Correct 7 ms 600 KB Output is correct
15 Correct 6 ms 604 KB Output is correct
16 Correct 5 ms 604 KB Output is correct
17 Correct 4 ms 604 KB Output is correct
18 Correct 4 ms 604 KB Output is correct
19 Correct 256 ms 13136 KB Output is correct
20 Correct 255 ms 13136 KB Output is correct
21 Correct 244 ms 14284 KB Output is correct
22 Correct 251 ms 18128 KB Output is correct
23 Correct 244 ms 18004 KB Output is correct
24 Correct 216 ms 15700 KB Output is correct
25 Correct 221 ms 15696 KB Output is correct
26 Correct 226 ms 16212 KB Output is correct
27 Correct 229 ms 16208 KB Output is correct
28 Correct 230 ms 16324 KB Output is correct
29 Correct 253 ms 16468 KB Output is correct
30 Correct 242 ms 16520 KB Output is correct
31 Correct 240 ms 16548 KB Output is correct
32 Correct 243 ms 16724 KB Output is correct
33 Correct 240 ms 16472 KB Output is correct
34 Correct 218 ms 15440 KB Output is correct
35 Correct 217 ms 15440 KB Output is correct
36 Correct 228 ms 15308 KB Output is correct
37 Correct 212 ms 15176 KB Output is correct
38 Correct 206 ms 15548 KB Output is correct
39 Correct 209 ms 15884 KB Output is correct
40 Correct 177 ms 12716 KB Output is correct
41 Correct 198 ms 15116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 4 ms 600 KB Output is correct
13 Correct 4 ms 604 KB Output is correct
14 Correct 7 ms 600 KB Output is correct
15 Correct 6 ms 604 KB Output is correct
16 Correct 5 ms 604 KB Output is correct
17 Correct 4 ms 604 KB Output is correct
18 Correct 4 ms 604 KB Output is correct
19 Correct 1463 ms 63556 KB Output is correct
20 Correct 1492 ms 63652 KB Output is correct
21 Correct 1493 ms 63556 KB Output is correct
22 Correct 1482 ms 63568 KB Output is correct
23 Correct 1369 ms 55352 KB Output is correct
24 Correct 106 ms 6740 KB Output is correct
25 Correct 95 ms 6480 KB Output is correct
26 Correct 93 ms 5972 KB Output is correct
27 Correct 90 ms 7596 KB Output is correct
28 Correct 95 ms 7508 KB Output is correct
29 Correct 79 ms 7300 KB Output is correct
30 Correct 83 ms 7232 KB Output is correct
31 Correct 81 ms 7308 KB Output is correct
32 Correct 50 ms 3596 KB Output is correct
33 Correct 98 ms 7312 KB Output is correct
34 Correct 256 ms 13136 KB Output is correct
35 Correct 255 ms 13136 KB Output is correct
36 Correct 244 ms 14284 KB Output is correct
37 Correct 251 ms 18128 KB Output is correct
38 Correct 244 ms 18004 KB Output is correct
39 Correct 216 ms 15700 KB Output is correct
40 Correct 221 ms 15696 KB Output is correct
41 Correct 226 ms 16212 KB Output is correct
42 Correct 229 ms 16208 KB Output is correct
43 Correct 230 ms 16324 KB Output is correct
44 Correct 253 ms 16468 KB Output is correct
45 Correct 242 ms 16520 KB Output is correct
46 Correct 240 ms 16548 KB Output is correct
47 Correct 243 ms 16724 KB Output is correct
48 Correct 240 ms 16472 KB Output is correct
49 Correct 218 ms 15440 KB Output is correct
50 Correct 217 ms 15440 KB Output is correct
51 Correct 228 ms 15308 KB Output is correct
52 Correct 212 ms 15176 KB Output is correct
53 Correct 206 ms 15548 KB Output is correct
54 Correct 209 ms 15884 KB Output is correct
55 Correct 177 ms 12716 KB Output is correct
56 Correct 198 ms 15116 KB Output is correct
57 Correct 1456 ms 88348 KB Output is correct
58 Correct 1483 ms 88408 KB Output is correct
59 Correct 1521 ms 86828 KB Output is correct
60 Correct 1480 ms 86956 KB Output is correct
61 Correct 1514 ms 86864 KB Output is correct
62 Correct 1580 ms 86964 KB Output is correct
63 Correct 1175 ms 76128 KB Output is correct
64 Correct 1282 ms 76128 KB Output is correct
65 Correct 1499 ms 70080 KB Output is correct
66 Correct 1507 ms 70172 KB Output is correct
67 Correct 1496 ms 70364 KB Output is correct
68 Correct 1674 ms 71716 KB Output is correct
69 Correct 1529 ms 71664 KB Output is correct
70 Correct 1409 ms 71428 KB Output is correct
71 Correct 1501 ms 71504 KB Output is correct
72 Correct 1513 ms 71428 KB Output is correct
73 Correct 1078 ms 64944 KB Output is correct
74 Correct 1107 ms 65368 KB Output is correct
75 Correct 1062 ms 67052 KB Output is correct
76 Correct 1093 ms 66844 KB Output is correct
77 Correct 1064 ms 66760 KB Output is correct
78 Correct 1132 ms 69792 KB Output is correct
79 Correct 893 ms 49404 KB Output is correct
80 Correct 1069 ms 66856 KB Output is correct