답안 #681044

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
681044 2023-01-12T09:46:25 Z Matteo_Verz Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1991 ms 79004 KB
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>

using namespace std;

struct Query {
    int l, r, w, idx, ans;
};

class SegTree {
    // Update: max= on element
    // Query: max on interval
private:
    vector <int> a;
    int n;

    void _update(int node, int l, int r, int pos, int val) {
        if (l == r) a[node] = max(a[node], val);
        else {
            int mid = (l + r) >> 1;
            if (pos <= mid) _update(node << 1, l, mid, pos, val);
            else _update(node << 1 | 1, mid + 1, r, pos, val);

            a[node] = max(a[node << 1], a[node << 1 | 1]);
        }
    }

    int _query(int node, int l, int r, int x, int y) {
        if (x <= l && r <= y)
            return a[node];

        int mid = (l + r) >> 1, ans = 0;
        if (x <= mid) ans = max(ans, _query(node << 1, l, mid, x, y));
        if (mid < y) ans = max(ans, _query(node << 1 | 1, mid + 1, r, x, y));

        return ans;
    }

public:
    SegTree(int _n) : n(_n) { a.resize(1 + 4 * _n); }

    void update(int pos, int value) {
        _update(1, 0, n - 1, pos, value);
    }

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

int main() {
    int n, k;
    cin >> n >> k;
    vector <int> v(n);
    vector <Query> q(k);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    for (int i = 0; i < k; i++) {
        cin >> q[i].l >> q[i].r >> q[i].w;
        q[i].l--; q[i].r--;
        q[i].idx = i;
    }

    sort(q.begin(), q.end(), [](Query a, Query b) {
        return a.r < b.r;
    });

    vector <int> rightpos(n, -1);
    stack <int> st;
    int j = 0;
    SegTree aint(n);
    for (int i = 0; i < n; i++) {
        while (st.size() && v[i] >= v[st.top()])
            st.pop();
        if (st.size()) {
            rightpos[st.top()] = i;
            aint.update(st.top(), v[st.top()] + v[i]);
        }

        st.push(i);

        while (j < k && q[j].r == i) {
            q[j].ans = aint.query(q[j].l, q[j].r);
            j++;
        }
    }

    sort(q.begin(), q.end(), [](Query a, Query b) {
        return a.idx < b.idx;
    });

    for (auto qi : q) {
        // cerr << qi.ans << '\n';
        if (qi.ans > qi.w)
            cout << 0 << '\n';
        else cout << 1 << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 6 ms 468 KB Output is correct
13 Correct 7 ms 468 KB Output is correct
14 Correct 9 ms 512 KB Output is correct
15 Correct 11 ms 468 KB Output is correct
16 Correct 7 ms 516 KB Output is correct
17 Correct 9 ms 468 KB Output is correct
18 Correct 6 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1862 ms 45268 KB Output is correct
2 Correct 1911 ms 78136 KB Output is correct
3 Correct 1893 ms 78032 KB Output is correct
4 Correct 1932 ms 78164 KB Output is correct
5 Correct 1773 ms 78136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 4700 KB Output is correct
2 Correct 138 ms 6740 KB Output is correct
3 Correct 132 ms 6720 KB Output is correct
4 Correct 148 ms 6844 KB Output is correct
5 Correct 130 ms 6736 KB Output is correct
6 Correct 127 ms 6592 KB Output is correct
7 Correct 162 ms 6600 KB Output is correct
8 Correct 117 ms 6472 KB Output is correct
9 Correct 89 ms 3776 KB Output is correct
10 Correct 133 ms 6356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 6 ms 468 KB Output is correct
13 Correct 7 ms 468 KB Output is correct
14 Correct 9 ms 512 KB Output is correct
15 Correct 11 ms 468 KB Output is correct
16 Correct 7 ms 516 KB Output is correct
17 Correct 9 ms 468 KB Output is correct
18 Correct 6 ms 468 KB Output is correct
19 Correct 361 ms 9296 KB Output is correct
20 Correct 379 ms 15864 KB Output is correct
21 Correct 427 ms 15868 KB Output is correct
22 Correct 349 ms 15728 KB Output is correct
23 Correct 347 ms 15744 KB Output is correct
24 Correct 342 ms 15600 KB Output is correct
25 Correct 329 ms 15588 KB Output is correct
26 Correct 347 ms 15820 KB Output is correct
27 Correct 340 ms 15732 KB Output is correct
28 Correct 405 ms 15792 KB Output is correct
29 Correct 372 ms 15860 KB Output is correct
30 Correct 360 ms 15900 KB Output is correct
31 Correct 353 ms 16020 KB Output is correct
32 Correct 382 ms 15924 KB Output is correct
33 Correct 342 ms 15948 KB Output is correct
34 Correct 313 ms 15468 KB Output is correct
35 Correct 324 ms 15608 KB Output is correct
36 Correct 330 ms 15224 KB Output is correct
37 Correct 311 ms 15324 KB Output is correct
38 Correct 336 ms 15484 KB Output is correct
39 Correct 317 ms 14540 KB Output is correct
40 Correct 274 ms 12164 KB Output is correct
41 Correct 282 ms 13936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 6 ms 468 KB Output is correct
13 Correct 7 ms 468 KB Output is correct
14 Correct 9 ms 512 KB Output is correct
15 Correct 11 ms 468 KB Output is correct
16 Correct 7 ms 516 KB Output is correct
17 Correct 9 ms 468 KB Output is correct
18 Correct 6 ms 468 KB Output is correct
19 Correct 1862 ms 45268 KB Output is correct
20 Correct 1911 ms 78136 KB Output is correct
21 Correct 1893 ms 78032 KB Output is correct
22 Correct 1932 ms 78164 KB Output is correct
23 Correct 1773 ms 78136 KB Output is correct
24 Correct 139 ms 4700 KB Output is correct
25 Correct 138 ms 6740 KB Output is correct
26 Correct 132 ms 6720 KB Output is correct
27 Correct 148 ms 6844 KB Output is correct
28 Correct 130 ms 6736 KB Output is correct
29 Correct 127 ms 6592 KB Output is correct
30 Correct 162 ms 6600 KB Output is correct
31 Correct 117 ms 6472 KB Output is correct
32 Correct 89 ms 3776 KB Output is correct
33 Correct 133 ms 6356 KB Output is correct
34 Correct 361 ms 9296 KB Output is correct
35 Correct 379 ms 15864 KB Output is correct
36 Correct 427 ms 15868 KB Output is correct
37 Correct 349 ms 15728 KB Output is correct
38 Correct 347 ms 15744 KB Output is correct
39 Correct 342 ms 15600 KB Output is correct
40 Correct 329 ms 15588 KB Output is correct
41 Correct 347 ms 15820 KB Output is correct
42 Correct 340 ms 15732 KB Output is correct
43 Correct 405 ms 15792 KB Output is correct
44 Correct 372 ms 15860 KB Output is correct
45 Correct 360 ms 15900 KB Output is correct
46 Correct 353 ms 16020 KB Output is correct
47 Correct 382 ms 15924 KB Output is correct
48 Correct 342 ms 15948 KB Output is correct
49 Correct 313 ms 15468 KB Output is correct
50 Correct 324 ms 15608 KB Output is correct
51 Correct 330 ms 15224 KB Output is correct
52 Correct 311 ms 15324 KB Output is correct
53 Correct 336 ms 15484 KB Output is correct
54 Correct 317 ms 14540 KB Output is correct
55 Correct 274 ms 12164 KB Output is correct
56 Correct 282 ms 13936 KB Output is correct
57 Correct 1975 ms 79004 KB Output is correct
58 Correct 1923 ms 78868 KB Output is correct
59 Correct 1884 ms 78772 KB Output is correct
60 Correct 1895 ms 78892 KB Output is correct
61 Correct 1930 ms 78804 KB Output is correct
62 Correct 1991 ms 78736 KB Output is correct
63 Correct 1719 ms 76920 KB Output is correct
64 Correct 1658 ms 76916 KB Output is correct
65 Correct 1796 ms 78784 KB Output is correct
66 Correct 1783 ms 78708 KB Output is correct
67 Correct 1785 ms 78788 KB Output is correct
68 Correct 1787 ms 78948 KB Output is correct
69 Correct 1863 ms 78852 KB Output is correct
70 Correct 1858 ms 78916 KB Output is correct
71 Correct 1884 ms 79000 KB Output is correct
72 Correct 1828 ms 78892 KB Output is correct
73 Correct 1675 ms 75440 KB Output is correct
74 Correct 1630 ms 76372 KB Output is correct
75 Correct 1608 ms 75564 KB Output is correct
76 Correct 1604 ms 75484 KB Output is correct
77 Correct 1678 ms 75332 KB Output is correct
78 Correct 1570 ms 72736 KB Output is correct
79 Correct 1381 ms 56752 KB Output is correct
80 Correct 1490 ms 69816 KB Output is correct