답안 #677751

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
677751 2023-01-04T09:53:50 Z Alcabel Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1171 ms 79460 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = (1 << 20);

struct SegTree {
    int n;
    int st[2 * maxn];
    SegTree() {}
    SegTree(int _n) {
        if (_n == 1) {
            n = _n;
        } else {
            n = (1 << (31 - __builtin_clz(_n - 1) + 1));
        }
        for (int i = 0; i < 2 * n; ++i) {
            st[i] = 0;
        }
    }
    void update(int v, int tl, int tr, int i, int val) {
        // cerr << "v: " << v << ", tl: " << tl << ", tr: " << tr << ", i: " << i << ", val: " << val << '\n';
        if (tl + 1 == tr) {
            st[v] = val;
            return;
        }
        int m = tl + (tr - tl) / 2;
        if (i < m) {
            update(2 * v, tl, m, i, val);
        } else {
            update(2 * v + 1, m, tr, i, val);
        }
        st[v] = max(st[2 * v], st[2 * v + 1]);
    }
    void update(int i, int val) {
        return update(1, 0, n, i, val);
    }
    int getMax(int v, int tl, int tr, int l, int r) {
        if (l <= tl && tr <= r) {
            return st[v];
        }
        int m = tl + (tr - tl) / 2, res = 0;
        if (l < m) {
            res = max(res, getMax(2 * v, tl, m, l, r));
        }
        if (m < r) {
            res = max(res, getMax(2 * v + 1, m, tr, l, r));
        }
        return res;
    }
    int getMax(int l, int r) {
        return getMax(1, 0, n, l, r);
    }
    ~SegTree() {}
};
int w[maxn], leftGr[maxn], ans[maxn];

struct Event {
    int l, r, idx;
    Event() {}
    Event(int _l, int _r, int _idx) {
        l = _l, r = _r, idx = _idx;
    }
    bool operator<(const Event& other) const {
        return make_pair(other.l, idx) < make_pair(l, other.idx);
    }
    ~Event() {}
};
Event evs[2 * maxn];

void solve() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }
    vector<int> stk;
    for (int i = 0; i < n; ++i) {
        while (!stk.empty() && w[i] >= w[stk.back()]) {
            stk.pop_back();
        }
        if (!stk.empty()) {
            leftGr[i] = stk.back();
        } else {
            leftGr[i] = -1;
        }
        stk.push_back(i);
        evs[i] = Event(leftGr[i], i, -1);
    }
    for (int i = 0; i < m; ++i) {
        cin >> evs[n + i].l >> evs[n + i].r >> ans[i];
        --evs[n + i].l, --evs[n + i].r;
        evs[n + i].idx = i;
    }
    sort(evs, evs + n + m);
    SegTree st(n);
    for (int i = 0; i < n + m && evs[i].l != -1; ++i) {
        if (evs[i].idx == -1) {
            st.update(evs[i].r, w[evs[i].l] + w[evs[i].r]);
        } else {
            //vcerr << "idx: " << evs[i].idx << '\n';
            //vcerr << "mx: " << st.getMax(evs[i].l, evs[i].r + 1) << '\n';
            if (st.getMax(evs[i].l, evs[i].r + 1) <= ans[evs[i].idx]) {
                ans[evs[i].idx] = 1;
            } else {
                ans[evs[i].idx] = 0;
            }
        }
    }
    for (int i = 0; i < m; ++i) {
        cout << ans[i] << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }

    return 0;
}

/*
4 1
4 3 5 1
1 4 6
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8532 KB Output is correct
2 Correct 3 ms 8532 KB Output is correct
3 Correct 4 ms 8532 KB Output is correct
4 Correct 4 ms 8532 KB Output is correct
5 Correct 4 ms 8532 KB Output is correct
6 Correct 4 ms 8488 KB Output is correct
7 Correct 4 ms 8532 KB Output is correct
8 Correct 5 ms 8532 KB Output is correct
9 Correct 4 ms 8532 KB Output is correct
10 Correct 4 ms 8532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8532 KB Output is correct
2 Correct 3 ms 8532 KB Output is correct
3 Correct 4 ms 8532 KB Output is correct
4 Correct 4 ms 8532 KB Output is correct
5 Correct 4 ms 8532 KB Output is correct
6 Correct 4 ms 8488 KB Output is correct
7 Correct 4 ms 8532 KB Output is correct
8 Correct 5 ms 8532 KB Output is correct
9 Correct 4 ms 8532 KB Output is correct
10 Correct 4 ms 8532 KB Output is correct
11 Correct 6 ms 8532 KB Output is correct
12 Correct 6 ms 8660 KB Output is correct
13 Correct 6 ms 8660 KB Output is correct
14 Correct 7 ms 8660 KB Output is correct
15 Correct 8 ms 8684 KB Output is correct
16 Correct 7 ms 8692 KB Output is correct
17 Correct 6 ms 8716 KB Output is correct
18 Correct 7 ms 8732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1145 ms 45672 KB Output is correct
2 Correct 1056 ms 45680 KB Output is correct
3 Correct 1062 ms 45684 KB Output is correct
4 Correct 1025 ms 45668 KB Output is correct
5 Correct 945 ms 68376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 12236 KB Output is correct
2 Correct 82 ms 12208 KB Output is correct
3 Correct 73 ms 12624 KB Output is correct
4 Correct 75 ms 14168 KB Output is correct
5 Correct 89 ms 14200 KB Output is correct
6 Correct 68 ms 14044 KB Output is correct
7 Correct 70 ms 14092 KB Output is correct
8 Correct 75 ms 13880 KB Output is correct
9 Correct 55 ms 11640 KB Output is correct
10 Correct 72 ms 13900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8532 KB Output is correct
2 Correct 3 ms 8532 KB Output is correct
3 Correct 4 ms 8532 KB Output is correct
4 Correct 4 ms 8532 KB Output is correct
5 Correct 4 ms 8532 KB Output is correct
6 Correct 4 ms 8488 KB Output is correct
7 Correct 4 ms 8532 KB Output is correct
8 Correct 5 ms 8532 KB Output is correct
9 Correct 4 ms 8532 KB Output is correct
10 Correct 4 ms 8532 KB Output is correct
11 Correct 6 ms 8532 KB Output is correct
12 Correct 6 ms 8660 KB Output is correct
13 Correct 6 ms 8660 KB Output is correct
14 Correct 7 ms 8660 KB Output is correct
15 Correct 8 ms 8684 KB Output is correct
16 Correct 7 ms 8692 KB Output is correct
17 Correct 6 ms 8716 KB Output is correct
18 Correct 7 ms 8732 KB Output is correct
19 Correct 198 ms 15972 KB Output is correct
20 Correct 193 ms 15972 KB Output is correct
21 Correct 208 ms 17812 KB Output is correct
22 Correct 189 ms 22380 KB Output is correct
23 Correct 217 ms 22416 KB Output is correct
24 Correct 157 ms 22296 KB Output is correct
25 Correct 156 ms 22316 KB Output is correct
26 Correct 174 ms 22484 KB Output is correct
27 Correct 162 ms 22468 KB Output is correct
28 Correct 172 ms 22500 KB Output is correct
29 Correct 169 ms 22756 KB Output is correct
30 Correct 157 ms 22536 KB Output is correct
31 Correct 162 ms 22476 KB Output is correct
32 Correct 171 ms 22476 KB Output is correct
33 Correct 165 ms 22580 KB Output is correct
34 Correct 161 ms 22092 KB Output is correct
35 Correct 158 ms 22140 KB Output is correct
36 Correct 157 ms 22000 KB Output is correct
37 Correct 149 ms 21924 KB Output is correct
38 Correct 174 ms 22200 KB Output is correct
39 Correct 152 ms 21068 KB Output is correct
40 Correct 119 ms 19112 KB Output is correct
41 Correct 147 ms 20800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8532 KB Output is correct
2 Correct 3 ms 8532 KB Output is correct
3 Correct 4 ms 8532 KB Output is correct
4 Correct 4 ms 8532 KB Output is correct
5 Correct 4 ms 8532 KB Output is correct
6 Correct 4 ms 8488 KB Output is correct
7 Correct 4 ms 8532 KB Output is correct
8 Correct 5 ms 8532 KB Output is correct
9 Correct 4 ms 8532 KB Output is correct
10 Correct 4 ms 8532 KB Output is correct
11 Correct 6 ms 8532 KB Output is correct
12 Correct 6 ms 8660 KB Output is correct
13 Correct 6 ms 8660 KB Output is correct
14 Correct 7 ms 8660 KB Output is correct
15 Correct 8 ms 8684 KB Output is correct
16 Correct 7 ms 8692 KB Output is correct
17 Correct 6 ms 8716 KB Output is correct
18 Correct 7 ms 8732 KB Output is correct
19 Correct 1145 ms 45672 KB Output is correct
20 Correct 1056 ms 45680 KB Output is correct
21 Correct 1062 ms 45684 KB Output is correct
22 Correct 1025 ms 45668 KB Output is correct
23 Correct 945 ms 68376 KB Output is correct
24 Correct 84 ms 12236 KB Output is correct
25 Correct 82 ms 12208 KB Output is correct
26 Correct 73 ms 12624 KB Output is correct
27 Correct 75 ms 14168 KB Output is correct
28 Correct 89 ms 14200 KB Output is correct
29 Correct 68 ms 14044 KB Output is correct
30 Correct 70 ms 14092 KB Output is correct
31 Correct 75 ms 13880 KB Output is correct
32 Correct 55 ms 11640 KB Output is correct
33 Correct 72 ms 13900 KB Output is correct
34 Correct 198 ms 15972 KB Output is correct
35 Correct 193 ms 15972 KB Output is correct
36 Correct 208 ms 17812 KB Output is correct
37 Correct 189 ms 22380 KB Output is correct
38 Correct 217 ms 22416 KB Output is correct
39 Correct 157 ms 22296 KB Output is correct
40 Correct 156 ms 22316 KB Output is correct
41 Correct 174 ms 22484 KB Output is correct
42 Correct 162 ms 22468 KB Output is correct
43 Correct 172 ms 22500 KB Output is correct
44 Correct 169 ms 22756 KB Output is correct
45 Correct 157 ms 22536 KB Output is correct
46 Correct 162 ms 22476 KB Output is correct
47 Correct 171 ms 22476 KB Output is correct
48 Correct 165 ms 22580 KB Output is correct
49 Correct 161 ms 22092 KB Output is correct
50 Correct 158 ms 22140 KB Output is correct
51 Correct 157 ms 22000 KB Output is correct
52 Correct 149 ms 21924 KB Output is correct
53 Correct 174 ms 22200 KB Output is correct
54 Correct 152 ms 21068 KB Output is correct
55 Correct 119 ms 19112 KB Output is correct
56 Correct 147 ms 20800 KB Output is correct
57 Correct 1171 ms 79460 KB Output is correct
58 Correct 1038 ms 79312 KB Output is correct
59 Correct 1016 ms 79164 KB Output is correct
60 Correct 1052 ms 79208 KB Output is correct
61 Correct 1010 ms 79320 KB Output is correct
62 Correct 981 ms 79184 KB Output is correct
63 Correct 782 ms 77336 KB Output is correct
64 Correct 777 ms 77352 KB Output is correct
65 Correct 836 ms 79148 KB Output is correct
66 Correct 856 ms 79272 KB Output is correct
67 Correct 861 ms 79164 KB Output is correct
68 Correct 916 ms 79428 KB Output is correct
69 Correct 883 ms 79432 KB Output is correct
70 Correct 866 ms 79284 KB Output is correct
71 Correct 896 ms 79384 KB Output is correct
72 Correct 887 ms 79360 KB Output is correct
73 Correct 759 ms 75912 KB Output is correct
74 Correct 808 ms 76872 KB Output is correct
75 Correct 779 ms 75788 KB Output is correct
76 Correct 778 ms 75816 KB Output is correct
77 Correct 782 ms 76108 KB Output is correct
78 Correct 840 ms 73136 KB Output is correct
79 Correct 607 ms 58968 KB Output is correct
80 Correct 828 ms 70380 KB Output is correct