제출 #1257310

#제출 시각아이디문제언어결과실행 시간메모리
1257310inkvizytorHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
100 / 100
896 ms84492 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

void ustaw(int v, ll x, vector<ll> &tr) {
    v += 1<<20;
    tr[v] = x;
    v /= 2;
    while (v > 0) {
        tr[v] = max(tr[v*2], tr[v*2+1]);
        v /= 2;
    }
}

ll maks(int v, int p, int k, vector<ll> &tr, int a, int b) {
    if (a <= p && k <= b) {
        return tr[v];
    }
    if (a > k || b < p) {
        return 0;
    }
    return max(maks(v*2, p, (p+k)/2, tr, a, b), maks(v*2+1, (p+k)/2+1, k, tr, a, b));
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<ll> w (n, 0);
    for (int i = 0; i < n; i++) {
        cin >> w[i];
    }
    vector<pair<ll, ll>> p (n);
    stack<pair<ll, ll>> s;
    for (int i = 0; i < n; i++) {
        while (!s.empty() && (s.top().second <= w[i])) {
            s.pop();
        }
        if (!s.empty()) {
            p[i] = {s.top().first, s.top().second+w[i]};
        }
        else {
            p[i] = {-1, -1};
        }
        s.push({i, w[i]});
    }
    vector<pair<pair<ll, ll>, pair<ll, ll>>> x (m);
    for (int i = 0; i < m; i++) {
        cin >> x[i].first.second >> x[i].first.first >> x[i].second.first;
        x[i].second.second = i;
        x[i].first.first--;
        x[i].first.second--;
    }
    sort(x.begin(), x.end());
    vector<ll> tr (1<<21, 0);
    int in = 0;
    vector<ll> wy (m, 0);
    for (int i = 0; i < n; i++) {
        if (p[i].first != -1) {
            ustaw(p[i].first, p[i].second, tr);
        }
        while (in < m && (x[in].first.first == i)) {
            wy[x[in].second.second] = maks(1, 0, (1<<20)-1, tr, x[in].first.second, i)<=(x[in].second.first);
            in++;
        }
    }
    for (int i : wy) {
        cout << i << '\n';
    }
}
#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...