Submission #1267818

#TimeUsernameProblemLanguageResultExecution timeMemory
1267818kawhietHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
0 / 100
3095 ms21996 KiB
#include <bits/stdc++.h>
using namespace std;

struct SegmentTree {
    int n;
    vector<int> st;

    SegmentTree(int sz) {
        n = sz;
        st.resize(4 * n);
    }

    int merge(int x, int y) {
        return max(x, y);
    }

    void build(vector<int> &a, int id, int tl, int tr) {
        if (tl == tr) {
            st[id] = a[tl];
            return;
        }
        int tm = (tl + tr ) / 2, x = 2 * id + 1, y = x + 1;
        build(a, x, tl, tm);
        build(a, y, tm + 1, tr);
        st[id] = merge(st[x], st[y]);
    }

    int get(int id, int tl, int tr, int l, int r) {
        if (r < tl || tr < l) return 0LL;
        if (l <= tl && tr <= r)
            return st[id];
        int tm = (tl + tr) / 2, x = 2 * id + 1, y = x + 1;
        return merge(get(x, tl, tm, l, r), get(y, tm + 1, tr, l, r));
    }

    int get(int l, int r) {
        return get(0, 0, n - 1, l, r);
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    SegmentTree st(n);
    st.build(a, 0, 0, n - 1);
    while (m--) {
        int l, r, k;
        cin >> l >> r >> k;
        l--; r--;
        int res = 0;
        for (int i = l + 1; i <= r; i++) {
            int mx = st.get(l, i - 1);
            if (mx > a[i]) {
                res = max(res, mx + a[i]);
            }
            if (res >= k) break;
        }
        cout << (res <= k) << '\n';
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...