Submission #943217

# Submission time Handle Problem Language Result Execution time Memory
943217 2024-03-11T09:22:12 Z MisterReaper Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
754 ms 92372 KB
#include <bits/stdc++.h>
using i64 = long long;

int lsb(int x) {
    return x & -x;
}

void solve() {
    int n, q;
    std::cin >> n >> q;

    std::vector<int> a(n + 1);
    a[0] = 1E9 + 5;
    for(int i = 1; i <= n; i++) {
        std::cin >> a[i];
    }

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

    std::vector<int> mx(n + 1);
    auto Update = [&](int p, int b) -> void {
        for(int i = p; i > 0; i -= lsb(i)) {
            mx[i] = std::max(mx[i], b);
        }
    };
    auto Query = [&](int p) -> int {
        int res = 0;
        for(int i = p; i <= n; i += lsb(i)) {
            res = std::max(res, mx[i]);
        }
        return res;
    };

    std::vector<int> st{0}, ans(q);
    for(int i = 1; i <= n; i++) {
        while(a[st.back()] <= a[i]) {
            st.pop_back();
        }
        Update(st.back(), a[st.back()] + a[i]);
        for(auto [l, k, idx] : qs[i]) {
            ans[idx] = Query(l) <= k;
        }
        st.emplace_back(i);
    }

    for(int i = 0; i < q; i++) {
        std::cout << ans[i] << "\n";
    }
    
    return;
}

signed main() {
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL); std::cout.tie(NULL);

    int t = 1; //std::cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 568 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 3 ms 584 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 670 ms 91088 KB Output is correct
2 Correct 754 ms 92040 KB Output is correct
3 Correct 692 ms 91988 KB Output is correct
4 Correct 706 ms 92244 KB Output is correct
5 Correct 647 ms 92244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 8272 KB Output is correct
2 Correct 37 ms 8028 KB Output is correct
3 Correct 37 ms 8004 KB Output is correct
4 Correct 38 ms 8128 KB Output is correct
5 Correct 37 ms 8272 KB Output is correct
6 Correct 32 ms 7504 KB Output is correct
7 Correct 30 ms 7512 KB Output is correct
8 Correct 36 ms 7692 KB Output is correct
9 Correct 22 ms 3788 KB Output is correct
10 Correct 34 ms 7692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 568 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 3 ms 584 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 94 ms 18604 KB Output is correct
20 Correct 93 ms 18516 KB Output is correct
21 Correct 87 ms 18244 KB Output is correct
22 Correct 86 ms 17812 KB Output is correct
23 Correct 100 ms 18024 KB Output is correct
24 Correct 90 ms 17872 KB Output is correct
25 Correct 76 ms 17744 KB Output is correct
26 Correct 88 ms 18152 KB Output is correct
27 Correct 85 ms 18068 KB Output is correct
28 Correct 90 ms 18208 KB Output is correct
29 Correct 90 ms 18636 KB Output is correct
30 Correct 87 ms 18516 KB Output is correct
31 Correct 108 ms 18508 KB Output is correct
32 Correct 91 ms 18620 KB Output is correct
33 Correct 88 ms 18492 KB Output is correct
34 Correct 73 ms 17340 KB Output is correct
35 Correct 74 ms 17232 KB Output is correct
36 Correct 72 ms 17236 KB Output is correct
37 Correct 73 ms 17128 KB Output is correct
38 Correct 73 ms 17236 KB Output is correct
39 Correct 84 ms 16812 KB Output is correct
40 Correct 71 ms 13576 KB Output is correct
41 Correct 96 ms 16384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 568 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 3 ms 584 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 670 ms 91088 KB Output is correct
20 Correct 754 ms 92040 KB Output is correct
21 Correct 692 ms 91988 KB Output is correct
22 Correct 706 ms 92244 KB Output is correct
23 Correct 647 ms 92244 KB Output is correct
24 Correct 40 ms 8272 KB Output is correct
25 Correct 37 ms 8028 KB Output is correct
26 Correct 37 ms 8004 KB Output is correct
27 Correct 38 ms 8128 KB Output is correct
28 Correct 37 ms 8272 KB Output is correct
29 Correct 32 ms 7504 KB Output is correct
30 Correct 30 ms 7512 KB Output is correct
31 Correct 36 ms 7692 KB Output is correct
32 Correct 22 ms 3788 KB Output is correct
33 Correct 34 ms 7692 KB Output is correct
34 Correct 94 ms 18604 KB Output is correct
35 Correct 93 ms 18516 KB Output is correct
36 Correct 87 ms 18244 KB Output is correct
37 Correct 86 ms 17812 KB Output is correct
38 Correct 100 ms 18024 KB Output is correct
39 Correct 90 ms 17872 KB Output is correct
40 Correct 76 ms 17744 KB Output is correct
41 Correct 88 ms 18152 KB Output is correct
42 Correct 85 ms 18068 KB Output is correct
43 Correct 90 ms 18208 KB Output is correct
44 Correct 90 ms 18636 KB Output is correct
45 Correct 87 ms 18516 KB Output is correct
46 Correct 108 ms 18508 KB Output is correct
47 Correct 91 ms 18620 KB Output is correct
48 Correct 88 ms 18492 KB Output is correct
49 Correct 73 ms 17340 KB Output is correct
50 Correct 74 ms 17232 KB Output is correct
51 Correct 72 ms 17236 KB Output is correct
52 Correct 73 ms 17128 KB Output is correct
53 Correct 73 ms 17236 KB Output is correct
54 Correct 84 ms 16812 KB Output is correct
55 Correct 71 ms 13576 KB Output is correct
56 Correct 96 ms 16384 KB Output is correct
57 Correct 660 ms 92244 KB Output is correct
58 Correct 706 ms 92200 KB Output is correct
59 Correct 630 ms 90708 KB Output is correct
60 Correct 703 ms 90688 KB Output is correct
61 Correct 616 ms 90616 KB Output is correct
62 Correct 665 ms 90784 KB Output is correct
63 Correct 434 ms 87672 KB Output is correct
64 Correct 403 ms 87500 KB Output is correct
65 Correct 613 ms 90560 KB Output is correct
66 Correct 565 ms 90536 KB Output is correct
67 Correct 608 ms 90784 KB Output is correct
68 Correct 677 ms 92212 KB Output is correct
69 Correct 674 ms 92372 KB Output is correct
70 Correct 639 ms 91896 KB Output is correct
71 Correct 631 ms 92040 KB Output is correct
72 Correct 612 ms 91884 KB Output is correct
73 Correct 371 ms 83288 KB Output is correct
74 Correct 387 ms 84612 KB Output is correct
75 Correct 395 ms 83312 KB Output is correct
76 Correct 407 ms 83576 KB Output is correct
77 Correct 404 ms 83568 KB Output is correct
78 Correct 592 ms 84572 KB Output is correct
79 Correct 464 ms 62476 KB Output is correct
80 Correct 582 ms 81784 KB Output is correct