Submission #964079

# Submission time Handle Problem Language Result Execution time Memory
964079 2024-04-16T09:38:43 Z zxcigan Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1194 ms 96584 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6 + 1;
const int mod = 1e9 + 7;

template <typename T>
bool umx(T& a, T b) {
    return (a < b ? a = b, 1 : 0);
}
template <typename T>
bool umn(T& a, T b) {
    return (a > b ? a = b, 1 : 0);
}
int t[4 * N];
vector<array<int,3>> query[N];
void update (int v, int tl, int tr, int pos, int x) {
    if (tl == tr) {
        umx (t[v], x);
        return;
    }
    int tm = (tr + tl) >> 1;
    if (pos <= tm) update (v << 1, tl, tm, pos, x);
    else update (v << 1 | 1, tm + 1, tr, pos, x);
    t[v] = max (t[v << 1], t[v << 1 | 1]);
}
int get (int v, int tl, int tr, int l, int r) {
    if (l > r) return 0;
    if (l == tl && r == tr) return t[v];
    int tm = (tr + tl) >> 1;
    return max (get (v << 1, tl, tm, l, min (r, tm)), get (v << 1 | 1, tm + 1, tr, max (l, tm + 1), r));
}
void solve () {
    int n, q;
    cin >> n >> q;
    vector<int> w (n + 1);
    for (int i = 1; i <= n; ++i) cin >> w[i];
    for (int i = 1; i <= q; ++i) {
        int l, r, k;
        cin >> l >> r >> k;
        query[r].push_back ({l, k, i});
    }
    vector<int> ans (q + 1);
    vector<int> ve;
    for (int right = 1; right <= n; ++right) {
        while ((int)ve.size() && w[ve.back()] <= w[right]) {
            ve.pop_back();
        }
        if ((int)ve.size()) update (1, 1, n, ve.back(), w[right] + w[ve.back()]);
        ve.push_back(right);
        for (auto [l, k, i] : query[right]) {
            ans[i] = bool(get (1, 1, n, l, right) <= k);
        }
    }
    for (int i = 1; i <= q; ++i) cout << ans[i] << '\n';
    cout << endl;
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    //    freopen ("input.txt", "r", stdin);
//    freopen ("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    while (T--) solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 25176 KB Output is correct
2 Correct 8 ms 25176 KB Output is correct
3 Correct 6 ms 25180 KB Output is correct
4 Correct 6 ms 25192 KB Output is correct
5 Correct 6 ms 25180 KB Output is correct
6 Correct 6 ms 25228 KB Output is correct
7 Correct 6 ms 25180 KB Output is correct
8 Correct 6 ms 25180 KB Output is correct
9 Correct 6 ms 25176 KB Output is correct
10 Correct 7 ms 25176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 25176 KB Output is correct
2 Correct 8 ms 25176 KB Output is correct
3 Correct 6 ms 25180 KB Output is correct
4 Correct 6 ms 25192 KB Output is correct
5 Correct 6 ms 25180 KB Output is correct
6 Correct 6 ms 25228 KB Output is correct
7 Correct 6 ms 25180 KB Output is correct
8 Correct 6 ms 25180 KB Output is correct
9 Correct 6 ms 25176 KB Output is correct
10 Correct 7 ms 25176 KB Output is correct
11 Correct 9 ms 25180 KB Output is correct
12 Correct 8 ms 25180 KB Output is correct
13 Correct 8 ms 25180 KB Output is correct
14 Correct 11 ms 25296 KB Output is correct
15 Correct 9 ms 25176 KB Output is correct
16 Correct 8 ms 25180 KB Output is correct
17 Correct 8 ms 25180 KB Output is correct
18 Correct 9 ms 25404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1109 ms 85592 KB Output is correct
2 Correct 1106 ms 96568 KB Output is correct
3 Correct 1120 ms 96248 KB Output is correct
4 Correct 1092 ms 96460 KB Output is correct
5 Correct 943 ms 89680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 28152 KB Output is correct
2 Correct 69 ms 27960 KB Output is correct
3 Correct 67 ms 28244 KB Output is correct
4 Correct 75 ms 28264 KB Output is correct
5 Correct 69 ms 28156 KB Output is correct
6 Correct 54 ms 27760 KB Output is correct
7 Correct 55 ms 27736 KB Output is correct
8 Correct 58 ms 28168 KB Output is correct
9 Correct 36 ms 27200 KB Output is correct
10 Correct 57 ms 28052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 25176 KB Output is correct
2 Correct 8 ms 25176 KB Output is correct
3 Correct 6 ms 25180 KB Output is correct
4 Correct 6 ms 25192 KB Output is correct
5 Correct 6 ms 25180 KB Output is correct
6 Correct 6 ms 25228 KB Output is correct
7 Correct 6 ms 25180 KB Output is correct
8 Correct 6 ms 25180 KB Output is correct
9 Correct 6 ms 25176 KB Output is correct
10 Correct 7 ms 25176 KB Output is correct
11 Correct 9 ms 25180 KB Output is correct
12 Correct 8 ms 25180 KB Output is correct
13 Correct 8 ms 25180 KB Output is correct
14 Correct 11 ms 25296 KB Output is correct
15 Correct 9 ms 25176 KB Output is correct
16 Correct 8 ms 25180 KB Output is correct
17 Correct 8 ms 25180 KB Output is correct
18 Correct 9 ms 25404 KB Output is correct
19 Correct 163 ms 36548 KB Output is correct
20 Correct 201 ms 38584 KB Output is correct
21 Correct 157 ms 38120 KB Output is correct
22 Correct 165 ms 37968 KB Output is correct
23 Correct 153 ms 37972 KB Output is correct
24 Correct 126 ms 37164 KB Output is correct
25 Correct 126 ms 37120 KB Output is correct
26 Correct 148 ms 37500 KB Output is correct
27 Correct 134 ms 37472 KB Output is correct
28 Correct 173 ms 37548 KB Output is correct
29 Correct 154 ms 38068 KB Output is correct
30 Correct 155 ms 37988 KB Output is correct
31 Correct 168 ms 37904 KB Output is correct
32 Correct 156 ms 37880 KB Output is correct
33 Correct 144 ms 38040 KB Output is correct
34 Correct 118 ms 36656 KB Output is correct
35 Correct 117 ms 36692 KB Output is correct
36 Correct 126 ms 36388 KB Output is correct
37 Correct 116 ms 36472 KB Output is correct
38 Correct 121 ms 36672 KB Output is correct
39 Correct 145 ms 37020 KB Output is correct
40 Correct 101 ms 34908 KB Output is correct
41 Correct 123 ms 35844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 25176 KB Output is correct
2 Correct 8 ms 25176 KB Output is correct
3 Correct 6 ms 25180 KB Output is correct
4 Correct 6 ms 25192 KB Output is correct
5 Correct 6 ms 25180 KB Output is correct
6 Correct 6 ms 25228 KB Output is correct
7 Correct 6 ms 25180 KB Output is correct
8 Correct 6 ms 25180 KB Output is correct
9 Correct 6 ms 25176 KB Output is correct
10 Correct 7 ms 25176 KB Output is correct
11 Correct 9 ms 25180 KB Output is correct
12 Correct 8 ms 25180 KB Output is correct
13 Correct 8 ms 25180 KB Output is correct
14 Correct 11 ms 25296 KB Output is correct
15 Correct 9 ms 25176 KB Output is correct
16 Correct 8 ms 25180 KB Output is correct
17 Correct 8 ms 25180 KB Output is correct
18 Correct 9 ms 25404 KB Output is correct
19 Correct 1109 ms 85592 KB Output is correct
20 Correct 1106 ms 96568 KB Output is correct
21 Correct 1120 ms 96248 KB Output is correct
22 Correct 1092 ms 96460 KB Output is correct
23 Correct 943 ms 89680 KB Output is correct
24 Correct 74 ms 28152 KB Output is correct
25 Correct 69 ms 27960 KB Output is correct
26 Correct 67 ms 28244 KB Output is correct
27 Correct 75 ms 28264 KB Output is correct
28 Correct 69 ms 28156 KB Output is correct
29 Correct 54 ms 27760 KB Output is correct
30 Correct 55 ms 27736 KB Output is correct
31 Correct 58 ms 28168 KB Output is correct
32 Correct 36 ms 27200 KB Output is correct
33 Correct 57 ms 28052 KB Output is correct
34 Correct 163 ms 36548 KB Output is correct
35 Correct 201 ms 38584 KB Output is correct
36 Correct 157 ms 38120 KB Output is correct
37 Correct 165 ms 37968 KB Output is correct
38 Correct 153 ms 37972 KB Output is correct
39 Correct 126 ms 37164 KB Output is correct
40 Correct 126 ms 37120 KB Output is correct
41 Correct 148 ms 37500 KB Output is correct
42 Correct 134 ms 37472 KB Output is correct
43 Correct 173 ms 37548 KB Output is correct
44 Correct 154 ms 38068 KB Output is correct
45 Correct 155 ms 37988 KB Output is correct
46 Correct 168 ms 37904 KB Output is correct
47 Correct 156 ms 37880 KB Output is correct
48 Correct 144 ms 38040 KB Output is correct
49 Correct 118 ms 36656 KB Output is correct
50 Correct 117 ms 36692 KB Output is correct
51 Correct 126 ms 36388 KB Output is correct
52 Correct 116 ms 36472 KB Output is correct
53 Correct 121 ms 36672 KB Output is correct
54 Correct 145 ms 37020 KB Output is correct
55 Correct 101 ms 34908 KB Output is correct
56 Correct 123 ms 35844 KB Output is correct
57 Correct 1194 ms 96584 KB Output is correct
58 Correct 1095 ms 96576 KB Output is correct
59 Correct 1020 ms 95040 KB Output is correct
60 Correct 1145 ms 95068 KB Output is correct
61 Correct 1052 ms 95128 KB Output is correct
62 Correct 1049 ms 95096 KB Output is correct
63 Correct 659 ms 85072 KB Output is correct
64 Correct 708 ms 84912 KB Output is correct
65 Correct 863 ms 88024 KB Output is correct
66 Correct 843 ms 87996 KB Output is correct
67 Correct 888 ms 88092 KB Output is correct
68 Correct 948 ms 89704 KB Output is correct
69 Correct 939 ms 89600 KB Output is correct
70 Correct 929 ms 89400 KB Output is correct
71 Correct 910 ms 89156 KB Output is correct
72 Correct 964 ms 89656 KB Output is correct
73 Correct 574 ms 80876 KB Output is correct
74 Correct 617 ms 81780 KB Output is correct
75 Correct 583 ms 80896 KB Output is correct
76 Correct 606 ms 81264 KB Output is correct
77 Correct 595 ms 80736 KB Output is correct
78 Correct 798 ms 84156 KB Output is correct
79 Correct 605 ms 73012 KB Output is correct
80 Correct 775 ms 80600 KB Output is correct