Submission #932107

# Submission time Handle Problem Language Result Execution time Memory
932107 2024-02-23T02:38:27 Z thangdz2k7 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
985 ms 104532 KB
#include <bits/stdc++.h>
#define pb push_back

using namespace std;

const int N = 1e6 + 5;

int n, m;
int a[N], u[N], v[N], k[N];
vector <int> ask[N];
int ans[N];

int Max[4 * N];

void upd(int s, int l, int r, int u, int v, int val){
    if (u <= l && r <= v){
        Max[s] = max(Max[s], val);
        return;
    }

    int mid = l + r >> 1;
    if (mid >= u) upd(2 * s, l, mid, u, v, val);
    if (mid + 1 <= v) upd(2 * s + 1, mid + 1, r, u, v, val);
}

int get(int s, int l, int r, int u){
    if (l == r) return Max[s];
    int mid = l + r >> 1;
    if (mid >= u) return max(Max[s], get(2 * s, l, mid, u));
    return max(Max[s], get(2 * s + 1, mid + 1, r, u));
}

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

    for (int i = 1; i <= m; ++ i){
        cin >> u[i] >> v[i] >> k[i];
        ask[v[i]].pb(i);
    }

    stack <int> st;
    for (int i = 1; i <= n; ++ i){
        while (!st.empty() && a[st.top()] <= a[i]) st.pop();
        if (!st.empty()) upd(1, 1, n, 1, st.top(), a[i] + a[st.top()]);
        st.push(i);

        for (int z : ask[i]) if (get(1, 1, n, u[z]) <= k[z]) ans[z] = 1;
    }

    for (int i = 1; i <= m; ++ i) cout << ans[i] << '\n';
}

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

    return 0;
}

Compilation message

sortbooks.cpp: In function 'void upd(int, int, int, int, int, int)':
sortbooks.cpp:21:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |     int mid = l + r >> 1;
      |               ~~^~~
sortbooks.cpp: In function 'int get(int, int, int, int)':
sortbooks.cpp:28:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |     int mid = l + r >> 1;
      |               ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Correct 6 ms 33116 KB Output is correct
3 Correct 7 ms 33116 KB Output is correct
4 Correct 7 ms 33112 KB Output is correct
5 Correct 6 ms 33116 KB Output is correct
6 Correct 7 ms 33204 KB Output is correct
7 Correct 7 ms 33116 KB Output is correct
8 Correct 9 ms 33116 KB Output is correct
9 Correct 8 ms 33116 KB Output is correct
10 Correct 7 ms 33116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Correct 6 ms 33116 KB Output is correct
3 Correct 7 ms 33116 KB Output is correct
4 Correct 7 ms 33112 KB Output is correct
5 Correct 6 ms 33116 KB Output is correct
6 Correct 7 ms 33204 KB Output is correct
7 Correct 7 ms 33116 KB Output is correct
8 Correct 9 ms 33116 KB Output is correct
9 Correct 8 ms 33116 KB Output is correct
10 Correct 7 ms 33116 KB Output is correct
11 Correct 9 ms 33424 KB Output is correct
12 Correct 8 ms 33372 KB Output is correct
13 Correct 9 ms 33524 KB Output is correct
14 Correct 9 ms 33372 KB Output is correct
15 Correct 9 ms 33372 KB Output is correct
16 Correct 9 ms 33528 KB Output is correct
17 Correct 9 ms 33368 KB Output is correct
18 Correct 10 ms 33372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 956 ms 72736 KB Output is correct
2 Correct 915 ms 72692 KB Output is correct
3 Correct 985 ms 70712 KB Output is correct
4 Correct 973 ms 70760 KB Output is correct
5 Correct 824 ms 64440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 38148 KB Output is correct
2 Correct 58 ms 39252 KB Output is correct
3 Correct 51 ms 38736 KB Output is correct
4 Correct 51 ms 38996 KB Output is correct
5 Correct 52 ms 38992 KB Output is correct
6 Correct 41 ms 35672 KB Output is correct
7 Correct 40 ms 35664 KB Output is correct
8 Correct 51 ms 38604 KB Output is correct
9 Correct 31 ms 37324 KB Output is correct
10 Correct 51 ms 38608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Correct 6 ms 33116 KB Output is correct
3 Correct 7 ms 33116 KB Output is correct
4 Correct 7 ms 33112 KB Output is correct
5 Correct 6 ms 33116 KB Output is correct
6 Correct 7 ms 33204 KB Output is correct
7 Correct 7 ms 33116 KB Output is correct
8 Correct 9 ms 33116 KB Output is correct
9 Correct 8 ms 33116 KB Output is correct
10 Correct 7 ms 33116 KB Output is correct
11 Correct 9 ms 33424 KB Output is correct
12 Correct 8 ms 33372 KB Output is correct
13 Correct 9 ms 33524 KB Output is correct
14 Correct 9 ms 33372 KB Output is correct
15 Correct 9 ms 33372 KB Output is correct
16 Correct 9 ms 33528 KB Output is correct
17 Correct 9 ms 33368 KB Output is correct
18 Correct 10 ms 33372 KB Output is correct
19 Correct 150 ms 51792 KB Output is correct
20 Correct 165 ms 51572 KB Output is correct
21 Correct 118 ms 49644 KB Output is correct
22 Correct 118 ms 49744 KB Output is correct
23 Correct 150 ms 49820 KB Output is correct
24 Correct 96 ms 47440 KB Output is correct
25 Correct 101 ms 47388 KB Output is correct
26 Correct 108 ms 48208 KB Output is correct
27 Correct 109 ms 48208 KB Output is correct
28 Correct 109 ms 48624 KB Output is correct
29 Correct 117 ms 49472 KB Output is correct
30 Correct 121 ms 49640 KB Output is correct
31 Correct 114 ms 49488 KB Output is correct
32 Correct 121 ms 49492 KB Output is correct
33 Correct 135 ms 49632 KB Output is correct
34 Correct 88 ms 47076 KB Output is correct
35 Correct 97 ms 47108 KB Output is correct
36 Correct 87 ms 46932 KB Output is correct
37 Correct 90 ms 46984 KB Output is correct
38 Correct 88 ms 47092 KB Output is correct
39 Correct 110 ms 48392 KB Output is correct
40 Correct 89 ms 46768 KB Output is correct
41 Correct 122 ms 47560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Correct 6 ms 33116 KB Output is correct
3 Correct 7 ms 33116 KB Output is correct
4 Correct 7 ms 33112 KB Output is correct
5 Correct 6 ms 33116 KB Output is correct
6 Correct 7 ms 33204 KB Output is correct
7 Correct 7 ms 33116 KB Output is correct
8 Correct 9 ms 33116 KB Output is correct
9 Correct 8 ms 33116 KB Output is correct
10 Correct 7 ms 33116 KB Output is correct
11 Correct 9 ms 33424 KB Output is correct
12 Correct 8 ms 33372 KB Output is correct
13 Correct 9 ms 33524 KB Output is correct
14 Correct 9 ms 33372 KB Output is correct
15 Correct 9 ms 33372 KB Output is correct
16 Correct 9 ms 33528 KB Output is correct
17 Correct 9 ms 33368 KB Output is correct
18 Correct 10 ms 33372 KB Output is correct
19 Correct 956 ms 72736 KB Output is correct
20 Correct 915 ms 72692 KB Output is correct
21 Correct 985 ms 70712 KB Output is correct
22 Correct 973 ms 70760 KB Output is correct
23 Correct 824 ms 64440 KB Output is correct
24 Correct 64 ms 38148 KB Output is correct
25 Correct 58 ms 39252 KB Output is correct
26 Correct 51 ms 38736 KB Output is correct
27 Correct 51 ms 38996 KB Output is correct
28 Correct 52 ms 38992 KB Output is correct
29 Correct 41 ms 35672 KB Output is correct
30 Correct 40 ms 35664 KB Output is correct
31 Correct 51 ms 38604 KB Output is correct
32 Correct 31 ms 37324 KB Output is correct
33 Correct 51 ms 38608 KB Output is correct
34 Correct 150 ms 51792 KB Output is correct
35 Correct 165 ms 51572 KB Output is correct
36 Correct 118 ms 49644 KB Output is correct
37 Correct 118 ms 49744 KB Output is correct
38 Correct 150 ms 49820 KB Output is correct
39 Correct 96 ms 47440 KB Output is correct
40 Correct 101 ms 47388 KB Output is correct
41 Correct 108 ms 48208 KB Output is correct
42 Correct 109 ms 48208 KB Output is correct
43 Correct 109 ms 48624 KB Output is correct
44 Correct 117 ms 49472 KB Output is correct
45 Correct 121 ms 49640 KB Output is correct
46 Correct 114 ms 49488 KB Output is correct
47 Correct 121 ms 49492 KB Output is correct
48 Correct 135 ms 49632 KB Output is correct
49 Correct 88 ms 47076 KB Output is correct
50 Correct 97 ms 47108 KB Output is correct
51 Correct 87 ms 46932 KB Output is correct
52 Correct 90 ms 46984 KB Output is correct
53 Correct 88 ms 47092 KB Output is correct
54 Correct 110 ms 48392 KB Output is correct
55 Correct 89 ms 46768 KB Output is correct
56 Correct 122 ms 47560 KB Output is correct
57 Correct 924 ms 104520 KB Output is correct
58 Correct 909 ms 104532 KB Output is correct
59 Correct 791 ms 100340 KB Output is correct
60 Correct 786 ms 100320 KB Output is correct
61 Correct 812 ms 100360 KB Output is correct
62 Correct 783 ms 100324 KB Output is correct
63 Correct 443 ms 84304 KB Output is correct
64 Correct 450 ms 84408 KB Output is correct
65 Correct 642 ms 91636 KB Output is correct
66 Correct 673 ms 91620 KB Output is correct
67 Correct 640 ms 91752 KB Output is correct
68 Correct 742 ms 96144 KB Output is correct
69 Correct 748 ms 96136 KB Output is correct
70 Correct 725 ms 95912 KB Output is correct
71 Correct 758 ms 95608 KB Output is correct
72 Correct 739 ms 95572 KB Output is correct
73 Correct 416 ms 82260 KB Output is correct
74 Correct 425 ms 83284 KB Output is correct
75 Correct 429 ms 82272 KB Output is correct
76 Correct 435 ms 82528 KB Output is correct
77 Correct 421 ms 82192 KB Output is correct
78 Correct 673 ms 91016 KB Output is correct
79 Correct 505 ms 79980 KB Output is correct
80 Correct 676 ms 86004 KB Output is correct