Submission #498612

# Submission time Handle Problem Language Result Execution time Memory
498612 2021-12-25T18:56:57 Z RedBoy Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++11
100 / 100
1292 ms 63916 KB
#include <iostream>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

const int N = 1e6 + 5;
const int INF = 2e9;

struct query{
    int ind, l, k;
};

int n, m;
int l[N], v[N], st[4 * N];
stack<int> s;
vector<query> q[N];
bitset<N> bit;

void update(int node, int l, int r, int pos, int val)
{
    if(l == r)
    {
        //cout << "UPDATE: " << node << ' ' << val << '\n';
        st[node] = max(st[node], val);
        return;
    }

    int lNode = node * 2, rNode = node * 2 + 1;
    int mid = (l + r) / 2;

    if(pos <= mid)
        update(lNode, l, mid, pos, val);
    else
        update(rNode, mid + 1, r, pos, val);

    st[node] = max(st[lNode], st[rNode]);
}

int get(int node, int l, int r, int ql, int qr)
{
    if(ql <= l && r <= qr)
        return st[node];

    int lNode = node * 2, rNode = node * 2 + 1, mid = (l + r) / 2, ans = -INF;
    if(ql <= mid)
        ans = max(ans, get(lNode, l, mid, ql, qr));
    if(qr > mid)
        ans = max(ans, get(rNode, mid + 1, r, ql, qr));

    return ans;
}

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

    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        cin >> v[i];
    for(int i = 1; i <= m; i++)
    {
        int l, r, k;
        cin >> l >> r >> k;
        q[r].push_back({i, l, k});
    }

    for(int i = 1; i <= n; i++)
    {
        l[i] = i;
        while(!s.empty() && v[i] >= v[s.top()])
        {
            l[i] = l[s.top()];
            s.pop();
        }
        s.push(i);
    }

    for(int i = 1; i <= n; i++)
    {
        //cout << "ARRAY: " << i << ' ' << l[i] - 1 << '\n';
        if(l[i] > 1)
            update(1, 1, n, l[i] - 1, v[i] + v[l[i] - 1]);
        for(auto it: q[i])
        {
            //cout << "QUERY: " << it.ind << ": " << it.l << ' ' << i << ' ' << it.k << '\n';
            //cout << get(1, 1, n, it.l, i) << "\n\n";
            bit[it.ind] = (it.k >= get(1, 1, n, it.l, i));
        }
    }

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

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23732 KB Output is correct
2 Correct 12 ms 23832 KB Output is correct
3 Correct 12 ms 23756 KB Output is correct
4 Correct 12 ms 23820 KB Output is correct
5 Correct 12 ms 23756 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 12 ms 23824 KB Output is correct
8 Correct 13 ms 23828 KB Output is correct
9 Correct 12 ms 23820 KB Output is correct
10 Correct 12 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23732 KB Output is correct
2 Correct 12 ms 23832 KB Output is correct
3 Correct 12 ms 23756 KB Output is correct
4 Correct 12 ms 23820 KB Output is correct
5 Correct 12 ms 23756 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 12 ms 23824 KB Output is correct
8 Correct 13 ms 23828 KB Output is correct
9 Correct 12 ms 23820 KB Output is correct
10 Correct 12 ms 23756 KB Output is correct
11 Correct 13 ms 23944 KB Output is correct
12 Correct 15 ms 24044 KB Output is correct
13 Correct 18 ms 23952 KB Output is correct
14 Correct 18 ms 24052 KB Output is correct
15 Correct 22 ms 24140 KB Output is correct
16 Correct 16 ms 24072 KB Output is correct
17 Correct 16 ms 23936 KB Output is correct
18 Correct 17 ms 24032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1292 ms 63852 KB Output is correct
2 Correct 1238 ms 63856 KB Output is correct
3 Correct 1200 ms 63916 KB Output is correct
4 Correct 1186 ms 63896 KB Output is correct
5 Correct 1029 ms 55492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 27972 KB Output is correct
2 Correct 92 ms 27812 KB Output is correct
3 Correct 84 ms 27308 KB Output is correct
4 Correct 93 ms 28764 KB Output is correct
5 Correct 95 ms 28956 KB Output is correct
6 Correct 76 ms 28296 KB Output is correct
7 Correct 74 ms 28380 KB Output is correct
8 Correct 85 ms 28484 KB Output is correct
9 Correct 47 ms 26812 KB Output is correct
10 Correct 82 ms 28480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23732 KB Output is correct
2 Correct 12 ms 23832 KB Output is correct
3 Correct 12 ms 23756 KB Output is correct
4 Correct 12 ms 23820 KB Output is correct
5 Correct 12 ms 23756 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 12 ms 23824 KB Output is correct
8 Correct 13 ms 23828 KB Output is correct
9 Correct 12 ms 23820 KB Output is correct
10 Correct 12 ms 23756 KB Output is correct
11 Correct 13 ms 23944 KB Output is correct
12 Correct 15 ms 24044 KB Output is correct
13 Correct 18 ms 23952 KB Output is correct
14 Correct 18 ms 24052 KB Output is correct
15 Correct 22 ms 24140 KB Output is correct
16 Correct 16 ms 24072 KB Output is correct
17 Correct 16 ms 23936 KB Output is correct
18 Correct 17 ms 24032 KB Output is correct
19 Correct 217 ms 32248 KB Output is correct
20 Correct 223 ms 32196 KB Output is correct
21 Correct 199 ms 33348 KB Output is correct
22 Correct 201 ms 37060 KB Output is correct
23 Correct 199 ms 36988 KB Output is correct
24 Correct 163 ms 34852 KB Output is correct
25 Correct 171 ms 34928 KB Output is correct
26 Correct 179 ms 35012 KB Output is correct
27 Correct 178 ms 35024 KB Output is correct
28 Correct 184 ms 35200 KB Output is correct
29 Correct 190 ms 35456 KB Output is correct
30 Correct 202 ms 35432 KB Output is correct
31 Correct 201 ms 35480 KB Output is correct
32 Correct 188 ms 35332 KB Output is correct
33 Correct 205 ms 35388 KB Output is correct
34 Correct 156 ms 34604 KB Output is correct
35 Correct 156 ms 34584 KB Output is correct
36 Correct 153 ms 34688 KB Output is correct
37 Correct 158 ms 34592 KB Output is correct
38 Correct 176 ms 34580 KB Output is correct
39 Correct 176 ms 35552 KB Output is correct
40 Correct 137 ms 33324 KB Output is correct
41 Correct 171 ms 34400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23732 KB Output is correct
2 Correct 12 ms 23832 KB Output is correct
3 Correct 12 ms 23756 KB Output is correct
4 Correct 12 ms 23820 KB Output is correct
5 Correct 12 ms 23756 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 12 ms 23824 KB Output is correct
8 Correct 13 ms 23828 KB Output is correct
9 Correct 12 ms 23820 KB Output is correct
10 Correct 12 ms 23756 KB Output is correct
11 Correct 13 ms 23944 KB Output is correct
12 Correct 15 ms 24044 KB Output is correct
13 Correct 18 ms 23952 KB Output is correct
14 Correct 18 ms 24052 KB Output is correct
15 Correct 22 ms 24140 KB Output is correct
16 Correct 16 ms 24072 KB Output is correct
17 Correct 16 ms 23936 KB Output is correct
18 Correct 17 ms 24032 KB Output is correct
19 Correct 1292 ms 63852 KB Output is correct
20 Correct 1238 ms 63856 KB Output is correct
21 Correct 1200 ms 63916 KB Output is correct
22 Correct 1186 ms 63896 KB Output is correct
23 Correct 1029 ms 55492 KB Output is correct
24 Correct 102 ms 27972 KB Output is correct
25 Correct 92 ms 27812 KB Output is correct
26 Correct 84 ms 27308 KB Output is correct
27 Correct 93 ms 28764 KB Output is correct
28 Correct 95 ms 28956 KB Output is correct
29 Correct 76 ms 28296 KB Output is correct
30 Correct 74 ms 28380 KB Output is correct
31 Correct 85 ms 28484 KB Output is correct
32 Correct 47 ms 26812 KB Output is correct
33 Correct 82 ms 28480 KB Output is correct
34 Correct 217 ms 32248 KB Output is correct
35 Correct 223 ms 32196 KB Output is correct
36 Correct 199 ms 33348 KB Output is correct
37 Correct 201 ms 37060 KB Output is correct
38 Correct 199 ms 36988 KB Output is correct
39 Correct 163 ms 34852 KB Output is correct
40 Correct 171 ms 34928 KB Output is correct
41 Correct 179 ms 35012 KB Output is correct
42 Correct 178 ms 35024 KB Output is correct
43 Correct 184 ms 35200 KB Output is correct
44 Correct 190 ms 35456 KB Output is correct
45 Correct 202 ms 35432 KB Output is correct
46 Correct 201 ms 35480 KB Output is correct
47 Correct 188 ms 35332 KB Output is correct
48 Correct 205 ms 35388 KB Output is correct
49 Correct 156 ms 34604 KB Output is correct
50 Correct 156 ms 34584 KB Output is correct
51 Correct 153 ms 34688 KB Output is correct
52 Correct 158 ms 34592 KB Output is correct
53 Correct 176 ms 34580 KB Output is correct
54 Correct 176 ms 35552 KB Output is correct
55 Correct 137 ms 33324 KB Output is correct
56 Correct 171 ms 34400 KB Output is correct
57 Correct 1201 ms 63884 KB Output is correct
58 Correct 1215 ms 63876 KB Output is correct
59 Correct 1127 ms 62424 KB Output is correct
60 Correct 1136 ms 62628 KB Output is correct
61 Correct 1150 ms 62460 KB Output is correct
62 Correct 1173 ms 62444 KB Output is correct
63 Correct 750 ms 52488 KB Output is correct
64 Correct 765 ms 52436 KB Output is correct
65 Correct 980 ms 54080 KB Output is correct
66 Correct 954 ms 54076 KB Output is correct
67 Correct 991 ms 54296 KB Output is correct
68 Correct 1014 ms 55644 KB Output is correct
69 Correct 1025 ms 55676 KB Output is correct
70 Correct 1025 ms 55428 KB Output is correct
71 Correct 1000 ms 55208 KB Output is correct
72 Correct 1024 ms 55524 KB Output is correct
73 Correct 709 ms 49824 KB Output is correct
74 Correct 722 ms 49812 KB Output is correct
75 Correct 710 ms 49988 KB Output is correct
76 Correct 725 ms 50076 KB Output is correct
77 Correct 712 ms 49836 KB Output is correct
78 Correct 902 ms 56224 KB Output is correct
79 Correct 685 ms 47720 KB Output is correct
80 Correct 915 ms 53616 KB Output is correct