Submission #1010990

# Submission time Handle Problem Language Result Execution time Memory
1010990 2024-06-29T16:29:43 Z phoenix Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
715 ms 101220 KB
#include <bits/stdc++.h>

using namespace std;
const int N = 1'000'100;
const int M = (1 << 20);

int tr[2 * M];
void update(int pos, int val) {
    for (tr[pos += M] = val; pos > 1; pos >>= 1)
        tr[pos >> 1] = max(tr[pos], tr[pos ^ 1]);
}
int get(int ql, int qr) {
    int res = 0;
    for (ql += M, qr += M + 1; ql < qr; ql >>= 1, qr >>= 1) {
        if (ql & 1) res = max(res, tr[ql++]);
        if (qr & 1) res = max(res, tr[--qr]);
    }
    return res;
}

int n, m;
int w[N];    
vector<int> qrs[N];

struct query {
    int l, r, k;
} Q[N];
bool res[N];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> w[i];
    for (int i = 1; i <= m; i++) {
        cin >> Q[i].l >> Q[i].r >> Q[i].k;
        qrs[Q[i].r].push_back(i);
    }

    vector<int> st;
    for (int r = 1; r <= n; r++) {
        while (!st.empty() && w[st.back()] <= w[r]) 
            st.pop_back();
        if (!st.empty()) 
            update(st.back(), w[st.back()] + w[r]);
        for (int i : qrs[r]) {
            res[i] = (get(Q[i].l, Q[i].r) <= Q[i].k);
        }
        st.push_back(r);
    }
    
    for (int i = 1; i <= m; i++)
        cout << res[i] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 33116 KB Output is correct
2 Correct 4 ms 29184 KB Output is correct
3 Correct 6 ms 33196 KB Output is correct
4 Correct 5 ms 33112 KB Output is correct
5 Correct 6 ms 33116 KB Output is correct
6 Correct 5 ms 33112 KB Output is correct
7 Correct 6 ms 33320 KB Output is correct
8 Correct 4 ms 29020 KB Output is correct
9 Correct 5 ms 29020 KB Output is correct
10 Correct 5 ms 29020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 33116 KB Output is correct
2 Correct 4 ms 29184 KB Output is correct
3 Correct 6 ms 33196 KB Output is correct
4 Correct 5 ms 33112 KB Output is correct
5 Correct 6 ms 33116 KB Output is correct
6 Correct 5 ms 33112 KB Output is correct
7 Correct 6 ms 33320 KB Output is correct
8 Correct 4 ms 29020 KB Output is correct
9 Correct 5 ms 29020 KB Output is correct
10 Correct 5 ms 29020 KB Output is correct
11 Correct 7 ms 33372 KB Output is correct
12 Correct 6 ms 33372 KB Output is correct
13 Correct 6 ms 33372 KB Output is correct
14 Correct 7 ms 33400 KB Output is correct
15 Correct 7 ms 33496 KB Output is correct
16 Correct 7 ms 29276 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 6 ms 29276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 715 ms 100320 KB Output is correct
2 Correct 661 ms 101200 KB Output is correct
3 Correct 713 ms 101088 KB Output is correct
4 Correct 684 ms 101220 KB Output is correct
5 Correct 588 ms 94292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 36944 KB Output is correct
2 Correct 45 ms 36184 KB Output is correct
3 Correct 42 ms 32760 KB Output is correct
4 Correct 42 ms 32824 KB Output is correct
5 Correct 40 ms 32896 KB Output is correct
6 Correct 39 ms 35824 KB Output is correct
7 Correct 33 ms 35924 KB Output is correct
8 Correct 36 ms 32460 KB Output is correct
9 Correct 26 ms 31192 KB Output is correct
10 Correct 40 ms 32484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 33116 KB Output is correct
2 Correct 4 ms 29184 KB Output is correct
3 Correct 6 ms 33196 KB Output is correct
4 Correct 5 ms 33112 KB Output is correct
5 Correct 6 ms 33116 KB Output is correct
6 Correct 5 ms 33112 KB Output is correct
7 Correct 6 ms 33320 KB Output is correct
8 Correct 4 ms 29020 KB Output is correct
9 Correct 5 ms 29020 KB Output is correct
10 Correct 5 ms 29020 KB Output is correct
11 Correct 7 ms 33372 KB Output is correct
12 Correct 6 ms 33372 KB Output is correct
13 Correct 6 ms 33372 KB Output is correct
14 Correct 7 ms 33400 KB Output is correct
15 Correct 7 ms 33496 KB Output is correct
16 Correct 7 ms 29276 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 6 ms 29276 KB Output is correct
19 Correct 117 ms 45652 KB Output is correct
20 Correct 93 ms 45652 KB Output is correct
21 Correct 82 ms 43856 KB Output is correct
22 Correct 82 ms 43624 KB Output is correct
23 Correct 85 ms 43856 KB Output is correct
24 Correct 74 ms 39348 KB Output is correct
25 Correct 78 ms 39504 KB Output is correct
26 Correct 91 ms 40392 KB Output is correct
27 Correct 85 ms 40276 KB Output is correct
28 Correct 92 ms 40532 KB Output is correct
29 Correct 102 ms 41560 KB Output is correct
30 Correct 101 ms 41556 KB Output is correct
31 Correct 90 ms 41556 KB Output is correct
32 Correct 94 ms 41364 KB Output is correct
33 Correct 99 ms 41552 KB Output is correct
34 Correct 70 ms 43268 KB Output is correct
35 Correct 67 ms 43092 KB Output is correct
36 Correct 87 ms 42832 KB Output is correct
37 Correct 73 ms 42836 KB Output is correct
38 Correct 75 ms 43108 KB Output is correct
39 Correct 89 ms 40140 KB Output is correct
40 Correct 74 ms 38740 KB Output is correct
41 Correct 80 ms 39492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 33116 KB Output is correct
2 Correct 4 ms 29184 KB Output is correct
3 Correct 6 ms 33196 KB Output is correct
4 Correct 5 ms 33112 KB Output is correct
5 Correct 6 ms 33116 KB Output is correct
6 Correct 5 ms 33112 KB Output is correct
7 Correct 6 ms 33320 KB Output is correct
8 Correct 4 ms 29020 KB Output is correct
9 Correct 5 ms 29020 KB Output is correct
10 Correct 5 ms 29020 KB Output is correct
11 Correct 7 ms 33372 KB Output is correct
12 Correct 6 ms 33372 KB Output is correct
13 Correct 6 ms 33372 KB Output is correct
14 Correct 7 ms 33400 KB Output is correct
15 Correct 7 ms 33496 KB Output is correct
16 Correct 7 ms 29276 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 6 ms 29276 KB Output is correct
19 Correct 715 ms 100320 KB Output is correct
20 Correct 661 ms 101200 KB Output is correct
21 Correct 713 ms 101088 KB Output is correct
22 Correct 684 ms 101220 KB Output is correct
23 Correct 588 ms 94292 KB Output is correct
24 Correct 47 ms 36944 KB Output is correct
25 Correct 45 ms 36184 KB Output is correct
26 Correct 42 ms 32760 KB Output is correct
27 Correct 42 ms 32824 KB Output is correct
28 Correct 40 ms 32896 KB Output is correct
29 Correct 39 ms 35824 KB Output is correct
30 Correct 33 ms 35924 KB Output is correct
31 Correct 36 ms 32460 KB Output is correct
32 Correct 26 ms 31192 KB Output is correct
33 Correct 40 ms 32484 KB Output is correct
34 Correct 117 ms 45652 KB Output is correct
35 Correct 93 ms 45652 KB Output is correct
36 Correct 82 ms 43856 KB Output is correct
37 Correct 82 ms 43624 KB Output is correct
38 Correct 85 ms 43856 KB Output is correct
39 Correct 74 ms 39348 KB Output is correct
40 Correct 78 ms 39504 KB Output is correct
41 Correct 91 ms 40392 KB Output is correct
42 Correct 85 ms 40276 KB Output is correct
43 Correct 92 ms 40532 KB Output is correct
44 Correct 102 ms 41560 KB Output is correct
45 Correct 101 ms 41556 KB Output is correct
46 Correct 90 ms 41556 KB Output is correct
47 Correct 94 ms 41364 KB Output is correct
48 Correct 99 ms 41552 KB Output is correct
49 Correct 70 ms 43268 KB Output is correct
50 Correct 67 ms 43092 KB Output is correct
51 Correct 87 ms 42832 KB Output is correct
52 Correct 73 ms 42836 KB Output is correct
53 Correct 75 ms 43108 KB Output is correct
54 Correct 89 ms 40140 KB Output is correct
55 Correct 74 ms 38740 KB Output is correct
56 Correct 80 ms 39492 KB Output is correct
57 Correct 630 ms 100140 KB Output is correct
58 Correct 618 ms 100132 KB Output is correct
59 Correct 542 ms 95992 KB Output is correct
60 Correct 590 ms 96060 KB Output is correct
61 Correct 553 ms 95928 KB Output is correct
62 Correct 521 ms 96080 KB Output is correct
63 Correct 389 ms 81496 KB Output is correct
64 Correct 389 ms 81524 KB Output is correct
65 Correct 512 ms 88848 KB Output is correct
66 Correct 513 ms 88540 KB Output is correct
67 Correct 500 ms 88928 KB Output is correct
68 Correct 592 ms 93264 KB Output is correct
69 Correct 571 ms 93264 KB Output is correct
70 Correct 540 ms 92496 KB Output is correct
71 Correct 576 ms 92496 KB Output is correct
72 Correct 551 ms 92616 KB Output is correct
73 Correct 351 ms 83548 KB Output is correct
74 Correct 341 ms 84316 KB Output is correct
75 Correct 340 ms 83432 KB Output is correct
76 Correct 374 ms 83792 KB Output is correct
77 Correct 369 ms 83492 KB Output is correct
78 Correct 547 ms 87548 KB Output is correct
79 Correct 374 ms 78328 KB Output is correct
80 Correct 467 ms 83252 KB Output is correct