답안 #825998

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
825998 2023-08-15T09:47:20 Z borisAngelov Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1533 ms 71684 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1000005;

int n, q;

int a[maxn];

struct query
{
    int l;
    int k;
    int idx;

    query()
    {

    }

    query(int _l, int _k, int _idx)
    {
        l = _l;
        k = _k;
        idx = _idx;
    }
};

vector<query> queries[maxn];
int answers[maxn];

struct segment_tree
{
    struct state
    {
        int maxv;
        int lazy;
    };

    state tree[4 * maxn];

    void push_lazy(int node, int l, int r)
    {
        if (tree[node].lazy == 0)
        {
            return;
        }

        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 val)
    {
        push_lazy(node, l, r);

        if (ql <= l && r <= qr)
        {
            tree[node].lazy = max(tree[node].lazy, val);
            push_lazy(node, l, r);
            return;
        }

        int mid = (l + r) / 2;

        if (ql <= mid)
        {
            update(2 * node, l, mid, ql, qr, val);
        }

        if (qr >= mid + 1)
        {
            update(2 * node + 1, mid + 1, r, ql, qr, val);
        }

        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)
    {
        push_lazy(node, l, r);

        if (ql <= l && r <= qr)
        {
            return tree[node].maxv;
        }

        int mid = (l + r) / 2;
        int result = 0;

        if (ql <= mid)
        {
            result = max(result, query(2 * node, l, mid, ql, qr));
        }

        if (qr >= mid + 1)
        {
            result = max(result, query(2 * node + 1, mid + 1, r, ql, qr));
        }

        return result;
    }

    void update(int l, int r, int val)
    {
        update(1, 1, n, l, r, val);
    }

    int query(int l, int r)
    {
        return query(1, 1, n, l, r);
    }
};

segment_tree 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];
    }

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

    stack<int> st;

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

        if (!st.empty())
        {
            tree.update(1, st.top(), a[i] + a[st.top()]);
        }

        for (int j = 0; j < queries[i].size(); ++j)
        {
            int l = queries[i][j].l;
            int idx = queries[i][j].idx;

            if (tree.query(l, i) <= queries[i][j].k)
            {
                answers[idx] = 1;
            }
            else
            {
                answers[idx] = 0;
            }
        }

        st.push(i);
    }

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

    return 0;
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:164:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  164 |         for (int j = 0; j < queries[i].size(); ++j)
      |                         ~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 23748 KB Output is correct
3 Incorrect 12 ms 23804 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 23748 KB Output is correct
3 Incorrect 12 ms 23804 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1533 ms 71684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 92 ms 28952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 23748 KB Output is correct
3 Incorrect 12 ms 23804 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 23748 KB Output is correct
3 Incorrect 12 ms 23804 KB Output isn't correct
4 Halted 0 ms 0 KB -