답안 #1111229

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111229 2024-11-11T19:22:43 Z borisAngelov Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1637 ms 177216 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 (ql <= l && r <= qr)
        {
            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, x, n, 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 55 ms 78740 KB Output is correct
2 Correct 62 ms 78724 KB Output is correct
3 Correct 53 ms 78664 KB Output is correct
4 Correct 53 ms 78780 KB Output is correct
5 Correct 54 ms 78684 KB Output is correct
6 Correct 52 ms 78672 KB Output is correct
7 Correct 55 ms 78768 KB Output is correct
8 Correct 54 ms 78664 KB Output is correct
9 Correct 63 ms 78708 KB Output is correct
10 Correct 56 ms 78664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 78740 KB Output is correct
2 Correct 62 ms 78724 KB Output is correct
3 Correct 53 ms 78664 KB Output is correct
4 Correct 53 ms 78780 KB Output is correct
5 Correct 54 ms 78684 KB Output is correct
6 Correct 52 ms 78672 KB Output is correct
7 Correct 55 ms 78768 KB Output is correct
8 Correct 54 ms 78664 KB Output is correct
9 Correct 63 ms 78708 KB Output is correct
10 Correct 56 ms 78664 KB Output is correct
11 Correct 56 ms 78720 KB Output is correct
12 Correct 57 ms 78948 KB Output is correct
13 Correct 57 ms 78980 KB Output is correct
14 Correct 63 ms 79052 KB Output is correct
15 Correct 59 ms 79144 KB Output is correct
16 Correct 58 ms 79048 KB Output is correct
17 Correct 57 ms 78932 KB Output is correct
18 Correct 58 ms 78940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1637 ms 166984 KB Output is correct
2 Correct 1630 ms 175736 KB Output is correct
3 Correct 1584 ms 175552 KB Output is correct
4 Correct 1555 ms 175728 KB Output is correct
5 Correct 1178 ms 155464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 85576 KB Output is correct
2 Correct 140 ms 87164 KB Output is correct
3 Correct 124 ms 85320 KB Output is correct
4 Correct 144 ms 85576 KB Output is correct
5 Correct 141 ms 85524 KB Output is correct
6 Correct 141 ms 83272 KB Output is correct
7 Correct 119 ms 83272 KB Output is correct
8 Correct 123 ms 85392 KB Output is correct
9 Correct 79 ms 81672 KB Output is correct
10 Correct 123 ms 85124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 78740 KB Output is correct
2 Correct 62 ms 78724 KB Output is correct
3 Correct 53 ms 78664 KB Output is correct
4 Correct 53 ms 78780 KB Output is correct
5 Correct 54 ms 78684 KB Output is correct
6 Correct 52 ms 78672 KB Output is correct
7 Correct 55 ms 78768 KB Output is correct
8 Correct 54 ms 78664 KB Output is correct
9 Correct 63 ms 78708 KB Output is correct
10 Correct 56 ms 78664 KB Output is correct
11 Correct 56 ms 78720 KB Output is correct
12 Correct 57 ms 78948 KB Output is correct
13 Correct 57 ms 78980 KB Output is correct
14 Correct 63 ms 79052 KB Output is correct
15 Correct 59 ms 79144 KB Output is correct
16 Correct 58 ms 79048 KB Output is correct
17 Correct 57 ms 78932 KB Output is correct
18 Correct 58 ms 78940 KB Output is correct
19 Correct 292 ms 99060 KB Output is correct
20 Correct 276 ms 99144 KB Output is correct
21 Correct 245 ms 98376 KB Output is correct
22 Correct 278 ms 98364 KB Output is correct
23 Correct 264 ms 98376 KB Output is correct
24 Correct 212 ms 90696 KB Output is correct
25 Correct 196 ms 90440 KB Output is correct
26 Correct 236 ms 93256 KB Output is correct
27 Correct 253 ms 93256 KB Output is correct
28 Correct 216 ms 94536 KB Output is correct
29 Correct 238 ms 95048 KB Output is correct
30 Correct 256 ms 95036 KB Output is correct
31 Correct 210 ms 94956 KB Output is correct
32 Correct 209 ms 95048 KB Output is correct
33 Correct 242 ms 95048 KB Output is correct
34 Correct 189 ms 89480 KB Output is correct
35 Correct 215 ms 89476 KB Output is correct
36 Correct 194 ms 89160 KB Output is correct
37 Correct 184 ms 89160 KB Output is correct
38 Correct 182 ms 89416 KB Output is correct
39 Correct 233 ms 94208 KB Output is correct
40 Correct 187 ms 89596 KB Output is correct
41 Correct 207 ms 93128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 78740 KB Output is correct
2 Correct 62 ms 78724 KB Output is correct
3 Correct 53 ms 78664 KB Output is correct
4 Correct 53 ms 78780 KB Output is correct
5 Correct 54 ms 78684 KB Output is correct
6 Correct 52 ms 78672 KB Output is correct
7 Correct 55 ms 78768 KB Output is correct
8 Correct 54 ms 78664 KB Output is correct
9 Correct 63 ms 78708 KB Output is correct
10 Correct 56 ms 78664 KB Output is correct
11 Correct 56 ms 78720 KB Output is correct
12 Correct 57 ms 78948 KB Output is correct
13 Correct 57 ms 78980 KB Output is correct
14 Correct 63 ms 79052 KB Output is correct
15 Correct 59 ms 79144 KB Output is correct
16 Correct 58 ms 79048 KB Output is correct
17 Correct 57 ms 78932 KB Output is correct
18 Correct 58 ms 78940 KB Output is correct
19 Correct 1637 ms 166984 KB Output is correct
20 Correct 1630 ms 175736 KB Output is correct
21 Correct 1584 ms 175552 KB Output is correct
22 Correct 1555 ms 175728 KB Output is correct
23 Correct 1178 ms 155464 KB Output is correct
24 Correct 146 ms 85576 KB Output is correct
25 Correct 140 ms 87164 KB Output is correct
26 Correct 124 ms 85320 KB Output is correct
27 Correct 144 ms 85576 KB Output is correct
28 Correct 141 ms 85524 KB Output is correct
29 Correct 141 ms 83272 KB Output is correct
30 Correct 119 ms 83272 KB Output is correct
31 Correct 123 ms 85392 KB Output is correct
32 Correct 79 ms 81672 KB Output is correct
33 Correct 123 ms 85124 KB Output is correct
34 Correct 292 ms 99060 KB Output is correct
35 Correct 276 ms 99144 KB Output is correct
36 Correct 245 ms 98376 KB Output is correct
37 Correct 278 ms 98364 KB Output is correct
38 Correct 264 ms 98376 KB Output is correct
39 Correct 212 ms 90696 KB Output is correct
40 Correct 196 ms 90440 KB Output is correct
41 Correct 236 ms 93256 KB Output is correct
42 Correct 253 ms 93256 KB Output is correct
43 Correct 216 ms 94536 KB Output is correct
44 Correct 238 ms 95048 KB Output is correct
45 Correct 256 ms 95036 KB Output is correct
46 Correct 210 ms 94956 KB Output is correct
47 Correct 209 ms 95048 KB Output is correct
48 Correct 242 ms 95048 KB Output is correct
49 Correct 189 ms 89480 KB Output is correct
50 Correct 215 ms 89476 KB Output is correct
51 Correct 194 ms 89160 KB Output is correct
52 Correct 184 ms 89160 KB Output is correct
53 Correct 182 ms 89416 KB Output is correct
54 Correct 233 ms 94208 KB Output is correct
55 Correct 187 ms 89596 KB Output is correct
56 Correct 207 ms 93128 KB Output is correct
57 Correct 1448 ms 177216 KB Output is correct
58 Correct 1433 ms 177188 KB Output is correct
59 Correct 1332 ms 174992 KB Output is correct
60 Correct 1387 ms 174916 KB Output is correct
61 Correct 1404 ms 175028 KB Output is correct
62 Correct 1390 ms 175008 KB Output is correct
63 Correct 802 ms 133192 KB Output is correct
64 Correct 803 ms 133316 KB Output is correct
65 Correct 1030 ms 153760 KB Output is correct
66 Correct 1039 ms 153876 KB Output is correct
67 Correct 1086 ms 154960 KB Output is correct
68 Correct 1131 ms 157084 KB Output is correct
69 Correct 1158 ms 157036 KB Output is correct
70 Correct 1170 ms 156396 KB Output is correct
71 Correct 1173 ms 156444 KB Output is correct
72 Correct 1253 ms 156552 KB Output is correct
73 Correct 746 ms 130380 KB Output is correct
74 Correct 827 ms 131400 KB Output is correct
75 Correct 794 ms 130472 KB Output is correct
76 Correct 751 ms 130336 KB Output is correct
77 Correct 762 ms 130480 KB Output is correct
78 Correct 1060 ms 153580 KB Output is correct
79 Correct 660 ms 130936 KB Output is correct
80 Correct 1085 ms 149548 KB Output is correct