답안 #1111200

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111200 2024-11-11T17:06:43 Z borisAngelov Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1546 ms 142656 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1000005;

int n, q;
int a[maxn], prvBigger[maxn];
vector<int> points[maxn];

vector<tuple<int, int, int>> queries[maxn];
string answers[maxn];

struct Node
{
    int maxv, lazy;
};

struct SegmentTree
{
    Node tree[4 * maxn];

    void pushLazy(int node, int l, int r)
    {
        tree[node].maxv = max(tree[node].maxv, tree[node].lazy);

        if (l != r)
        {
            tree[2 * node].lazy = max(tree[2 * node].lazy, tree[node].lazy);
            tree[2 * node + 1].lazy = max(tree[2 * node + 1].lazy, tree[node].lazy);
        }

        tree[node].lazy = 0;
    }

    void update(int node, int l, int r, int ql, int qr, int value)
    {
        pushLazy(node, l, r);
        if (l > qr || r < ql) return;
        if (l == r)
        {
            tree[node].lazy = max(tree[node].lazy, value);
            pushLazy(node, l, r);
            return;
        }

        int mid = (l + r) / 2;

        update(2 * node, l, mid, ql, qr, value);
        update(2 * node + 1, mid + 1, r, ql, qr, value);

        tree[node].maxv = max(tree[2 * node].maxv, tree[2 * node + 1].maxv);
    }

    int query(int node, int l, int r, int ql, int qr)
    {
        pushLazy(node, l, r);
        if (l > qr || r < ql) return 0;
        if (ql <= l && r <= qr) return tree[node].maxv;

        int mid = (l + r) / 2;
        return max(query(2 * node, l, mid, ql, qr), query(2 * node + 1, mid + 1, r, ql, qr));
    }
};

SegmentTree tree;

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fastIO();

    cin >> n >> q;

    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
    }

    stack<int> st;

    for (int i = 1; i <= n; ++i)
    {
        while (!st.empty() && a[st.top()] <= a[i]) st.pop();

        if (!st.empty())
        {
            prvBigger[i] = st.top();
            points[st.top()].push_back(i);
        }

        st.push(i);
    }

    for (int i = 1; i <= q; ++i)
    {
        int l, r, k;
        cin >> l >> r >> k;
        queries[l].push_back({r, k, i});
    }

    for (int i = n; i >= 1; --i)
    {
        for (auto x : points[i])
        {
            tree.update(1, 1, n, i, x, a[i] + a[x]);
            //cout << "add " << i << " " << x << " :: " << a[i] + a[x] << endl;
        }

        for (auto [r, k, idx] : queries[i])
        {
            //cout << i << " " << r << " :: " << tree.query(1, 1, n, i, r) << endl;
            if (tree.query(1, 1, n, i, r) <= k) answers[idx] = "1";
            else answers[idx] = "0";
        }
    }

    for (int i = 1; i <= q; ++i) cout << answers[i] << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 79952 KB Output is correct
2 Correct 34 ms 80088 KB Output is correct
3 Incorrect 38 ms 79944 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 79952 KB Output is correct
2 Correct 34 ms 80088 KB Output is correct
3 Incorrect 38 ms 79944 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1546 ms 142656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 139 ms 86600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 79952 KB Output is correct
2 Correct 34 ms 80088 KB Output is correct
3 Incorrect 38 ms 79944 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 79952 KB Output is correct
2 Correct 34 ms 80088 KB Output is correct
3 Incorrect 38 ms 79944 KB Output isn't correct
4 Halted 0 ms 0 KB -