Submission #501790

# Submission time Handle Problem Language Result Execution time Memory
501790 2022-01-04T14:52:55 Z dxz05 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
569 ms 100128 KB
#include <bits/stdc++.h>

using namespace std;

int t[4000005];

void update(int v, int tl, int tr, int pos, int val){
    if (tl == tr){
        t[v] = max(t[v], val);
        return;
    }
    int tm = (tl + tr) >> 1;
    if (pos <= tm) update(v + v, tl, tm, pos, val); else
        update(v + v + 1, tm + 1, tr, pos, val);

    t[v] = max(t[v + v], t[v + v + 1]);
}

int get(int v, int tl, int tr, int l, int r){
    if (l <= tl && tr <= r) return t[v];
    if (tl > r || tr < l) return 0;
    int tm = (tl + tr) >> 1;
    return max(get(v + v, tl, tm, l, r), get(v + v + 1, tm + 1, tr, l, r));
}

int a[1000005];
vector<pair<int, pair<int, int>>> queries[1000005];

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

    int n, q;
    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].emplace_back(l, make_pair(k, i));
    }

    bitset<200001> ans;

    a[0] = 2e9;
    stack<int> st;
    st.push(0);
    for (int i = 1; i <= n; i++){
        while (!st.empty() && a[st.top()] <= a[i]) st.pop();
        int j = st.top();
        if (j != 0) update(1, 1, n, j, a[j] + a[i]);

        for (auto qu : queries[i]){
            int l = qu.first, k = qu.second.first, ind = qu.second.second;
            ans[ind] = get(1, 1, n, l, i) <= k;
        }

        st.push(i);
    }

    for (int i = 1; i <= q; i++) cout << ans[i] << '\n';


    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 12 ms 23824 KB Output is correct
5 Correct 13 ms 23748 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 14 ms 23756 KB Output is correct
8 Correct 14 ms 23856 KB Output is correct
9 Correct 13 ms 23736 KB Output is correct
10 Correct 13 ms 23824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 12 ms 23824 KB Output is correct
5 Correct 13 ms 23748 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 14 ms 23756 KB Output is correct
8 Correct 14 ms 23856 KB Output is correct
9 Correct 13 ms 23736 KB Output is correct
10 Correct 13 ms 23824 KB Output is correct
11 Correct 14 ms 23884 KB Output is correct
12 Correct 15 ms 23988 KB Output is correct
13 Correct 15 ms 23880 KB Output is correct
14 Correct 16 ms 24040 KB Output is correct
15 Correct 16 ms 23992 KB Output is correct
16 Correct 15 ms 23956 KB Output is correct
17 Correct 17 ms 23940 KB Output is correct
18 Correct 16 ms 23884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 569 ms 100128 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 107 ms 27576 KB Output is correct
2 Correct 89 ms 27232 KB Output is correct
3 Correct 78 ms 26344 KB Output is correct
4 Correct 78 ms 26416 KB Output is correct
5 Correct 78 ms 26472 KB Output is correct
6 Correct 69 ms 26112 KB Output is correct
7 Correct 84 ms 26052 KB Output is correct
8 Correct 76 ms 26448 KB Output is correct
9 Correct 45 ms 25396 KB Output is correct
10 Correct 74 ms 26496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 12 ms 23824 KB Output is correct
5 Correct 13 ms 23748 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 14 ms 23756 KB Output is correct
8 Correct 14 ms 23856 KB Output is correct
9 Correct 13 ms 23736 KB Output is correct
10 Correct 13 ms 23824 KB Output is correct
11 Correct 14 ms 23884 KB Output is correct
12 Correct 15 ms 23988 KB Output is correct
13 Correct 15 ms 23880 KB Output is correct
14 Correct 16 ms 24040 KB Output is correct
15 Correct 16 ms 23992 KB Output is correct
16 Correct 15 ms 23956 KB Output is correct
17 Correct 17 ms 23940 KB Output is correct
18 Correct 16 ms 23884 KB Output is correct
19 Correct 236 ms 31444 KB Output is correct
20 Correct 200 ms 31180 KB Output is correct
21 Correct 174 ms 30684 KB Output is correct
22 Correct 183 ms 30920 KB Output is correct
23 Correct 177 ms 30736 KB Output is correct
24 Correct 146 ms 28612 KB Output is correct
25 Correct 146 ms 28640 KB Output is correct
26 Correct 166 ms 28840 KB Output is correct
27 Correct 160 ms 28808 KB Output is correct
28 Correct 166 ms 28864 KB Output is correct
29 Correct 190 ms 29296 KB Output is correct
30 Correct 170 ms 29124 KB Output is correct
31 Correct 167 ms 29088 KB Output is correct
32 Correct 177 ms 29200 KB Output is correct
33 Correct 173 ms 29172 KB Output is correct
34 Correct 152 ms 28332 KB Output is correct
35 Correct 146 ms 28336 KB Output is correct
36 Correct 140 ms 28484 KB Output is correct
37 Correct 136 ms 28356 KB Output is correct
38 Correct 144 ms 28388 KB Output is correct
39 Correct 157 ms 29560 KB Output is correct
40 Correct 122 ms 28228 KB Output is correct
41 Correct 155 ms 29148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 12 ms 23824 KB Output is correct
5 Correct 13 ms 23748 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 14 ms 23756 KB Output is correct
8 Correct 14 ms 23856 KB Output is correct
9 Correct 13 ms 23736 KB Output is correct
10 Correct 13 ms 23824 KB Output is correct
11 Correct 14 ms 23884 KB Output is correct
12 Correct 15 ms 23988 KB Output is correct
13 Correct 15 ms 23880 KB Output is correct
14 Correct 16 ms 24040 KB Output is correct
15 Correct 16 ms 23992 KB Output is correct
16 Correct 15 ms 23956 KB Output is correct
17 Correct 17 ms 23940 KB Output is correct
18 Correct 16 ms 23884 KB Output is correct
19 Runtime error 569 ms 100128 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -