Submission #651279

#TimeUsernameProblemLanguageResultExecution timeMemory
651279becaidoHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
890 ms61512 KiB
#pragma GCC optimize("O3")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define Waimai ios::sync_with_stdio(false),cin.tie(0)
#define FOR(x,a,b) for(int x=a,I=b;x<=I;x++)
#define pb emplace_back
#define F first
#define S second

const int SIZE = 1e6 + 5;

int n, q;
int a[SIZE], bit[SIZE];
bool ans[SIZE];
vector<pair<int, int>> st;
vector<tuple<int, int, int>> ask[SIZE];

void upd (int pos, int x) {
    for (; pos; pos -= pos & -pos) bit[pos] = max (bit[pos], x);
}

int que (int pos) {
    int re = 0;
    for (; pos <= n; pos += pos & -pos) re = max (re, bit[pos]);
    return re;
}

void solve() {
    cin >> n >> q;
    FOR (i, 1, n) cin >> a[i];
    FOR (i, 1, q) {
        int l, r, k;
        cin >> l >> r >> k;
        ask[r].pb (l, k, i);
    }
    FOR (i, 1, n) {
        while (st.size() && a[i] >= st.back().S) st.pop_back();
        if (st.size()) upd (st.back().F, st.back().S + a[i]);
        st.pb (i, a[i]);
        for (auto [l, k, id] : ask[i]) ans[id] = que (l) <= k;
    }
    FOR (i, 1, q) cout << ans[i] << '\n';
}

int main() {
    Waimai;
    solve();
}
#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...