Submission #1112991

# Submission time Handle Problem Language Result Execution time Memory
1112991 2024-11-15T11:02:08 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1981 ms 96584 KB
#include <bits/stdc++.h>
using namespace std;
 
const int maxn = 1e6 + 5;
 
int tree[4*maxn], n, q;
 
void U(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) U(2*u, tl, tm, p, v);
        else U(2*u+1, tm+1, tr, p, v);
        tree[u] = max(tree[2*u], tree[2*u+1]);
    }
}
 
int Q(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(Q(2*u, tl, tm, l, r), Q(2*u+1, tm+1, tr, l, r));
}
 
int main() {
    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()) U(1, 1, n, st.top(), v[st.top()] + v[i]);
        for(auto &[l, k, id] : qus[i]) ans[id] = (Q(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 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 4 ms 592 KB Output is correct
12 Correct 5 ms 716 KB Output is correct
13 Correct 6 ms 724 KB Output is correct
14 Correct 12 ms 848 KB Output is correct
15 Correct 9 ms 848 KB Output is correct
16 Correct 11 ms 848 KB Output is correct
17 Correct 5 ms 592 KB Output is correct
18 Correct 6 ms 792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1913 ms 95240 KB Output is correct
2 Correct 1955 ms 96320 KB Output is correct
3 Correct 1974 ms 96392 KB Output is correct
4 Correct 1981 ms 96452 KB Output is correct
5 Correct 1789 ms 88252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 8652 KB Output is correct
2 Correct 105 ms 8624 KB Output is correct
3 Correct 112 ms 7676 KB Output is correct
4 Correct 121 ms 7624 KB Output is correct
5 Correct 115 ms 7752 KB Output is correct
6 Correct 91 ms 7224 KB Output is correct
7 Correct 89 ms 7240 KB Output is correct
8 Correct 90 ms 7424 KB Output is correct
9 Correct 54 ms 3584 KB Output is correct
10 Correct 97 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 4 ms 592 KB Output is correct
12 Correct 5 ms 716 KB Output is correct
13 Correct 6 ms 724 KB Output is correct
14 Correct 12 ms 848 KB Output is correct
15 Correct 9 ms 848 KB Output is correct
16 Correct 11 ms 848 KB Output is correct
17 Correct 5 ms 592 KB Output is correct
18 Correct 6 ms 792 KB Output is correct
19 Correct 313 ms 19856 KB Output is correct
20 Correct 302 ms 19832 KB Output is correct
21 Correct 293 ms 19264 KB Output is correct
22 Correct 276 ms 19272 KB Output is correct
23 Correct 272 ms 19272 KB Output is correct
24 Correct 239 ms 16968 KB Output is correct
25 Correct 241 ms 16968 KB Output is correct
26 Correct 260 ms 17480 KB Output is correct
27 Correct 267 ms 17348 KB Output is correct
28 Correct 283 ms 17480 KB Output is correct
29 Correct 292 ms 17736 KB Output is correct
30 Correct 287 ms 17732 KB Output is correct
31 Correct 268 ms 17872 KB Output is correct
32 Correct 268 ms 17740 KB Output is correct
33 Correct 259 ms 17736 KB Output is correct
34 Correct 216 ms 16456 KB Output is correct
35 Correct 219 ms 16460 KB Output is correct
36 Correct 229 ms 16456 KB Output is correct
37 Correct 216 ms 16456 KB Output is correct
38 Correct 220 ms 16580 KB Output is correct
39 Correct 249 ms 16716 KB Output is correct
40 Correct 190 ms 13052 KB Output is correct
41 Correct 228 ms 15872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 4 ms 592 KB Output is correct
12 Correct 5 ms 716 KB Output is correct
13 Correct 6 ms 724 KB Output is correct
14 Correct 12 ms 848 KB Output is correct
15 Correct 9 ms 848 KB Output is correct
16 Correct 11 ms 848 KB Output is correct
17 Correct 5 ms 592 KB Output is correct
18 Correct 6 ms 792 KB Output is correct
19 Correct 1913 ms 95240 KB Output is correct
20 Correct 1955 ms 96320 KB Output is correct
21 Correct 1974 ms 96392 KB Output is correct
22 Correct 1981 ms 96452 KB Output is correct
23 Correct 1789 ms 88252 KB Output is correct
24 Correct 117 ms 8652 KB Output is correct
25 Correct 105 ms 8624 KB Output is correct
26 Correct 112 ms 7676 KB Output is correct
27 Correct 121 ms 7624 KB Output is correct
28 Correct 115 ms 7752 KB Output is correct
29 Correct 91 ms 7224 KB Output is correct
30 Correct 89 ms 7240 KB Output is correct
31 Correct 90 ms 7424 KB Output is correct
32 Correct 54 ms 3584 KB Output is correct
33 Correct 97 ms 7424 KB Output is correct
34 Correct 313 ms 19856 KB Output is correct
35 Correct 302 ms 19832 KB Output is correct
36 Correct 293 ms 19264 KB Output is correct
37 Correct 276 ms 19272 KB Output is correct
38 Correct 272 ms 19272 KB Output is correct
39 Correct 239 ms 16968 KB Output is correct
40 Correct 241 ms 16968 KB Output is correct
41 Correct 260 ms 17480 KB Output is correct
42 Correct 267 ms 17348 KB Output is correct
43 Correct 283 ms 17480 KB Output is correct
44 Correct 292 ms 17736 KB Output is correct
45 Correct 287 ms 17732 KB Output is correct
46 Correct 268 ms 17872 KB Output is correct
47 Correct 268 ms 17740 KB Output is correct
48 Correct 259 ms 17736 KB Output is correct
49 Correct 216 ms 16456 KB Output is correct
50 Correct 219 ms 16460 KB Output is correct
51 Correct 229 ms 16456 KB Output is correct
52 Correct 216 ms 16456 KB Output is correct
53 Correct 220 ms 16580 KB Output is correct
54 Correct 249 ms 16716 KB Output is correct
55 Correct 190 ms 13052 KB Output is correct
56 Correct 228 ms 15872 KB Output is correct
57 Correct 1738 ms 96564 KB Output is correct
58 Correct 1735 ms 96584 KB Output is correct
59 Correct 1570 ms 95100 KB Output is correct
60 Correct 1570 ms 95148 KB Output is correct
61 Correct 1624 ms 94980 KB Output is correct
62 Correct 1502 ms 94912 KB Output is correct
63 Correct 1205 ms 83652 KB Output is correct
64 Correct 1248 ms 83528 KB Output is correct
65 Correct 1447 ms 86616 KB Output is correct
66 Correct 1483 ms 86600 KB Output is correct
67 Correct 1435 ms 86856 KB Output is correct
68 Correct 1522 ms 88392 KB Output is correct
69 Correct 1517 ms 88300 KB Output is correct
70 Correct 1386 ms 88136 KB Output is correct
71 Correct 1605 ms 88120 KB Output is correct
72 Correct 1668 ms 88136 KB Output is correct
73 Correct 1132 ms 81592 KB Output is correct
74 Correct 1187 ms 82504 KB Output is correct
75 Correct 1144 ms 81664 KB Output is correct
76 Correct 1135 ms 81580 KB Output is correct
77 Correct 1233 ms 81460 KB Output is correct
78 Correct 1237 ms 83164 KB Output is correct
79 Correct 990 ms 60772 KB Output is correct
80 Correct 1301 ms 77912 KB Output is correct