Submission #332995

#TimeUsernameProblemLanguageResultExecution timeMemory
332995BoabaHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
17 / 100
3076 ms68648 KiB
#include <iostream>
#include <vector>
#define Max(a, b) (((a) < (b)) ? (b) : (a))

const int nmax = 1e6 + 5;

struct day {
    int st, dr, k, ind;
} q[nmax];

int v[nmax], ans[nmax], last[nmax], aint[4*nmax];
std::vector<int>st;
std::vector<day>skema[nmax];

void update(int node, int st, int dr, int x, int val) {
    if (x<st or x>dr) return;
    if (st == dr and st == x) {
        aint[node] = Max(aint[node], val); return;
    }
    int mij = (st + dr) >> 1;
    update(node << 1, st, mij, x, val);
    update(node << 1 | 1, mij + 1, dr, x, val);
    aint[node] = Max(aint[node << 1], aint[node << 1 | 1]);
}

int query(int node, int st, int dr, int x, int y) {
    if (y<st or x>dr) return 0;
    if (x <= st and dr <= y) return aint[node];
    int mij = (st + dr) >> 1;
    return Max(query(node << 1, st, mij, x, y), query(node << 1 | 1, mij + 1, dr, x, y));
}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    int n, m;
    std::cin >> n >> m;
    for (int i = 1; i <= n; i++) std::cin >> v[i];
    st.push_back(n);
    for (int i = n - 1; i >= 1; i--) {
        while (!st.empty() and v[st.back()] < v[i]) last[st.back()] = i, st.pop_back();
        st.push_back(i);
    }
    for (int i = 1; i <= m; i++) {
        day aux;
        std::cin >> aux.st >> aux.dr >> aux.k, aux.ind = i;
        skema[aux.dr].push_back(aux);
    }
    for (int i = 1; i <= n; i++) {
        if (last[i] != 0) update(1, 1, n, last[i], v[i] + v[last[i]]);
        for (auto aux : skema[i]) ans[aux.ind] = (query(1, 1, n, aux.st, aux.dr) <= aux.k);
    }
    for (int i = 1; i <= m; i++) std::cout << ans[i] << "\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...