답안 #874384

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
874384 2023-11-16T20:06:24 Z Macker Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1160 ms 102724 KB
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <math.h>
#include <tuple>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
#include <stack>
#include <climits>
#include <cassert>

using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()

vector<int> st;
int len = 1;

int query(int f, int t, int i = 1, int s = 0, int e = len) {
    if (f >= e || t <= s) return { INT_MIN };
    if (f <= s && e <= t) return st[i];
    return max(query(f, t, i * 2, s, (s + e) / 2), query(f, t, i * 2 + 1, (s + e) / 2, e));
}

void upd(int idx, int val, int i = 1, int s = 0, int e = len) {
    if (idx >= e || idx < s) return;
    if (idx == s && s + 1 == e) {
        st[i] = max(st[i], val); 
        return;
    }
    upd(idx, val, i * 2, s, (s + e) / 2);
    upd(idx, val, i * 2 + 1, (s + e) / 2, e);
    st[i] = max(st[i * 2], st[i * 2 + 1]);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q; cin >> n >> q;
    vector<int> v(n);
    for (auto& i : v) {
        cin >> i;
    }
    while (len < n) len *= 2;
    st.resize(2 * len, INT_MIN);
    vector<bool> ans(q);
    vector<tuple<int, int, int>> qry;
    vector<vector<pair<int, int>>> ls(n+1);
    for (int i = 0; i < q; i++) {
        int f, t, k; cin >> f >> t >> k;
        qry.push_back({ f, t, k });
        ls[t].push_back({ f, i });
    }

    stack<pair<int, int>> s;
    s.push({ INT_MAX, 0 });
    for (int i = 0; i < n; i++) {
        while (v[i] >= s.top().first) s.pop();
        upd(s.top().second, s.top().first + v[i]);
        s.push({ v[i], i + 1});

        for (auto& f : ls[i + 1]) {
            ans[f.second] = (query(f.first, len+1) <= get<2>(qry[f.second]));
        }
    }

    for (int i = 0; i < q; i++) {
        cout << ans[i] << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 4 ms 840 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 4 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1047 ms 69748 KB Output is correct
2 Correct 1160 ms 69608 KB Output is correct
3 Correct 1076 ms 69572 KB Output is correct
4 Correct 1095 ms 102496 KB Output is correct
5 Correct 1127 ms 102632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 7436 KB Output is correct
2 Correct 63 ms 8780 KB Output is correct
3 Correct 65 ms 9224 KB Output is correct
4 Correct 66 ms 9372 KB Output is correct
5 Correct 70 ms 9376 KB Output is correct
6 Correct 52 ms 8404 KB Output is correct
7 Correct 57 ms 8392 KB Output is correct
8 Correct 58 ms 9096 KB Output is correct
9 Correct 28 ms 3932 KB Output is correct
10 Correct 59 ms 9220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 4 ms 840 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 4 ms 856 KB Output is correct
19 Correct 172 ms 21544 KB Output is correct
20 Correct 165 ms 21088 KB Output is correct
21 Correct 145 ms 19712 KB Output is correct
22 Correct 142 ms 19724 KB Output is correct
23 Correct 147 ms 19716 KB Output is correct
24 Correct 125 ms 19456 KB Output is correct
25 Correct 153 ms 19568 KB Output is correct
26 Correct 134 ms 20808 KB Output is correct
27 Correct 136 ms 20736 KB Output is correct
28 Correct 149 ms 20944 KB Output is correct
29 Correct 144 ms 21132 KB Output is correct
30 Correct 143 ms 21372 KB Output is correct
31 Correct 170 ms 20988 KB Output is correct
32 Correct 147 ms 20992 KB Output is correct
33 Correct 156 ms 21252 KB Output is correct
34 Correct 139 ms 19224 KB Output is correct
35 Correct 125 ms 19200 KB Output is correct
36 Correct 120 ms 18900 KB Output is correct
37 Correct 145 ms 18924 KB Output is correct
38 Correct 130 ms 19184 KB Output is correct
39 Correct 139 ms 19176 KB Output is correct
40 Correct 109 ms 15888 KB Output is correct
41 Correct 143 ms 19224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 4 ms 840 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 4 ms 856 KB Output is correct
19 Correct 1047 ms 69748 KB Output is correct
20 Correct 1160 ms 69608 KB Output is correct
21 Correct 1076 ms 69572 KB Output is correct
22 Correct 1095 ms 102496 KB Output is correct
23 Correct 1127 ms 102632 KB Output is correct
24 Correct 67 ms 7436 KB Output is correct
25 Correct 63 ms 8780 KB Output is correct
26 Correct 65 ms 9224 KB Output is correct
27 Correct 66 ms 9372 KB Output is correct
28 Correct 70 ms 9376 KB Output is correct
29 Correct 52 ms 8404 KB Output is correct
30 Correct 57 ms 8392 KB Output is correct
31 Correct 58 ms 9096 KB Output is correct
32 Correct 28 ms 3932 KB Output is correct
33 Correct 59 ms 9220 KB Output is correct
34 Correct 172 ms 21544 KB Output is correct
35 Correct 165 ms 21088 KB Output is correct
36 Correct 145 ms 19712 KB Output is correct
37 Correct 142 ms 19724 KB Output is correct
38 Correct 147 ms 19716 KB Output is correct
39 Correct 125 ms 19456 KB Output is correct
40 Correct 153 ms 19568 KB Output is correct
41 Correct 134 ms 20808 KB Output is correct
42 Correct 136 ms 20736 KB Output is correct
43 Correct 149 ms 20944 KB Output is correct
44 Correct 144 ms 21132 KB Output is correct
45 Correct 143 ms 21372 KB Output is correct
46 Correct 170 ms 20988 KB Output is correct
47 Correct 147 ms 20992 KB Output is correct
48 Correct 156 ms 21252 KB Output is correct
49 Correct 139 ms 19224 KB Output is correct
50 Correct 125 ms 19200 KB Output is correct
51 Correct 120 ms 18900 KB Output is correct
52 Correct 145 ms 18924 KB Output is correct
53 Correct 130 ms 19184 KB Output is correct
54 Correct 139 ms 19176 KB Output is correct
55 Correct 109 ms 15888 KB Output is correct
56 Correct 143 ms 19224 KB Output is correct
57 Correct 1098 ms 102380 KB Output is correct
58 Correct 1113 ms 101992 KB Output is correct
59 Correct 1004 ms 99356 KB Output is correct
60 Correct 991 ms 99352 KB Output is correct
61 Correct 1066 ms 99008 KB Output is correct
62 Correct 965 ms 99408 KB Output is correct
63 Correct 679 ms 93948 KB Output is correct
64 Correct 647 ms 93796 KB Output is correct
65 Correct 941 ms 98976 KB Output is correct
66 Correct 902 ms 99020 KB Output is correct
67 Correct 949 ms 99176 KB Output is correct
68 Correct 1052 ms 102324 KB Output is correct
69 Correct 1081 ms 102724 KB Output is correct
70 Correct 996 ms 101492 KB Output is correct
71 Correct 979 ms 101592 KB Output is correct
72 Correct 994 ms 101760 KB Output is correct
73 Correct 640 ms 90784 KB Output is correct
74 Correct 630 ms 91876 KB Output is correct
75 Correct 641 ms 90640 KB Output is correct
76 Correct 675 ms 90828 KB Output is correct
77 Correct 642 ms 90504 KB Output is correct
78 Correct 864 ms 94208 KB Output is correct
79 Correct 631 ms 70124 KB Output is correct
80 Correct 839 ms 92912 KB Output is correct