Submission #581423

# Submission time Handle Problem Language Result Execution time Memory
581423 2022-06-22T15:49:02 Z islingr Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1251 ms 137376 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include "bits/stdc++.h"

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

#define rep(i, a, b) for (auto i{a}; i < (b); ++i)
#define per(i, a, b) for (auto i{b}; i-- > (a);)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())

template <class T>
bool uin(T& a, const T& b) {
    return a > b ? a = b, true : false;
}
template <class T>
bool uax(T& a, const T& b) {
    return a < b ? a = b, true : false;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct segment_tree {
    static constexpr int inf = 1e9;
    int n;
    vector<int> t;
    segment_tree() {}
    segment_tree(int n) : n{n}, t(2 * n, -inf) {}
    int query(int l, int r) {
        int res = -inf;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) res = max(res, t[l++]);
            if (r & 1) res = max(res, t[--r]);
        }
        return res;
    }
    void update(int p, int x) {
        for (t[p += n] = x; p >>= 1;) t[p] = max(t[p << 1], t[p << 1 | 1]);
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (auto& x : a) cin >> x;

    vector<int> p(n);  // p[i] = last (strictly) greater element than a[i]
    rep(i, 0, n) {
        p[i] = i - 1;
        while (p[i] >= 0 && a[i] >= a[p[i]]) p[i] = p[p[i]];
    }

    segment_tree t(n);
    vector<vector<int>> g(n);
    rep(i, 0, n) {
        if (p[i] < 0) continue;
        t.update(i, a[i] + a[p[i]]);
        g[p[i]].push_back(i);
    }

    vector<vector<tuple<int, int, int>>> queries(n);
    rep(i, 0, m) {
        int l, r, k;
        cin >> l >> r >> k;
        queries[l - 1].emplace_back(r, k, i);
    }

    vector<bool> ans(m);
    rep(l, 0, n) {
        for (auto [r, k, i] : queries[l]) ans[i] = t.query(l, r) <= k;
        for (auto c : g[l]) t.update(c, 0);
    }
    rep(i, 0, m) cout << ans[i] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 5 ms 724 KB Output is correct
15 Correct 4 ms 724 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 3 ms 612 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1146 ms 124640 KB Output is correct
2 Correct 1157 ms 135876 KB Output is correct
3 Correct 1157 ms 135636 KB Output is correct
4 Correct 1140 ms 135772 KB Output is correct
5 Correct 987 ms 119660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 10572 KB Output is correct
2 Correct 75 ms 11056 KB Output is correct
3 Correct 64 ms 10804 KB Output is correct
4 Correct 73 ms 10888 KB Output is correct
5 Correct 72 ms 11032 KB Output is correct
6 Correct 59 ms 10388 KB Output is correct
7 Correct 51 ms 10308 KB Output is correct
8 Correct 64 ms 10620 KB Output is correct
9 Correct 38 ms 3400 KB Output is correct
10 Correct 80 ms 10632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 5 ms 724 KB Output is correct
15 Correct 4 ms 724 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 3 ms 612 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 225 ms 23588 KB Output is correct
20 Correct 202 ms 27636 KB Output is correct
21 Correct 183 ms 26824 KB Output is correct
22 Correct 193 ms 26844 KB Output is correct
23 Correct 190 ms 27040 KB Output is correct
24 Correct 162 ms 23500 KB Output is correct
25 Correct 143 ms 23540 KB Output is correct
26 Correct 178 ms 23740 KB Output is correct
27 Correct 164 ms 23756 KB Output is correct
28 Correct 167 ms 23756 KB Output is correct
29 Correct 190 ms 24352 KB Output is correct
30 Correct 200 ms 24264 KB Output is correct
31 Correct 171 ms 24288 KB Output is correct
32 Correct 184 ms 24268 KB Output is correct
33 Correct 169 ms 24248 KB Output is correct
34 Correct 133 ms 22728 KB Output is correct
35 Correct 131 ms 22736 KB Output is correct
36 Correct 130 ms 22516 KB Output is correct
37 Correct 121 ms 22588 KB Output is correct
38 Correct 144 ms 22824 KB Output is correct
39 Correct 165 ms 23196 KB Output is correct
40 Correct 121 ms 16952 KB Output is correct
41 Correct 148 ms 22380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 5 ms 724 KB Output is correct
15 Correct 4 ms 724 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 3 ms 612 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 1146 ms 124640 KB Output is correct
20 Correct 1157 ms 135876 KB Output is correct
21 Correct 1157 ms 135636 KB Output is correct
22 Correct 1140 ms 135772 KB Output is correct
23 Correct 987 ms 119660 KB Output is correct
24 Correct 83 ms 10572 KB Output is correct
25 Correct 75 ms 11056 KB Output is correct
26 Correct 64 ms 10804 KB Output is correct
27 Correct 73 ms 10888 KB Output is correct
28 Correct 72 ms 11032 KB Output is correct
29 Correct 59 ms 10388 KB Output is correct
30 Correct 51 ms 10308 KB Output is correct
31 Correct 64 ms 10620 KB Output is correct
32 Correct 38 ms 3400 KB Output is correct
33 Correct 80 ms 10632 KB Output is correct
34 Correct 225 ms 23588 KB Output is correct
35 Correct 202 ms 27636 KB Output is correct
36 Correct 183 ms 26824 KB Output is correct
37 Correct 193 ms 26844 KB Output is correct
38 Correct 190 ms 27040 KB Output is correct
39 Correct 162 ms 23500 KB Output is correct
40 Correct 143 ms 23540 KB Output is correct
41 Correct 178 ms 23740 KB Output is correct
42 Correct 164 ms 23756 KB Output is correct
43 Correct 167 ms 23756 KB Output is correct
44 Correct 190 ms 24352 KB Output is correct
45 Correct 200 ms 24264 KB Output is correct
46 Correct 171 ms 24288 KB Output is correct
47 Correct 184 ms 24268 KB Output is correct
48 Correct 169 ms 24248 KB Output is correct
49 Correct 133 ms 22728 KB Output is correct
50 Correct 131 ms 22736 KB Output is correct
51 Correct 130 ms 22516 KB Output is correct
52 Correct 121 ms 22588 KB Output is correct
53 Correct 144 ms 22824 KB Output is correct
54 Correct 165 ms 23196 KB Output is correct
55 Correct 121 ms 16952 KB Output is correct
56 Correct 148 ms 22380 KB Output is correct
57 Correct 1168 ms 137376 KB Output is correct
58 Correct 1251 ms 137284 KB Output is correct
59 Correct 1121 ms 135296 KB Output is correct
60 Correct 1113 ms 135248 KB Output is correct
61 Correct 1146 ms 135212 KB Output is correct
62 Correct 1112 ms 135208 KB Output is correct
63 Correct 678 ms 113256 KB Output is correct
64 Correct 755 ms 113328 KB Output is correct
65 Correct 995 ms 118984 KB Output is correct
66 Correct 1038 ms 118928 KB Output is correct
67 Correct 996 ms 118892 KB Output is correct
68 Correct 1046 ms 121064 KB Output is correct
69 Correct 1082 ms 121072 KB Output is correct
70 Correct 1085 ms 120684 KB Output is correct
71 Correct 1041 ms 120528 KB Output is correct
72 Correct 1051 ms 120636 KB Output is correct
73 Correct 654 ms 110960 KB Output is correct
74 Correct 661 ms 111844 KB Output is correct
75 Correct 640 ms 111080 KB Output is correct
76 Correct 636 ms 110940 KB Output is correct
77 Correct 639 ms 111064 KB Output is correct
78 Correct 975 ms 116316 KB Output is correct
79 Correct 702 ms 74916 KB Output is correct
80 Correct 973 ms 110764 KB Output is correct