Submission #861920

# Submission time Handle Problem Language Result Execution time Memory
861920 2023-10-17T07:39:30 Z velislavgarkov Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1040 ms 94964 KB
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
#define endl '\n'
const int MAXN=1e6+10;
struct Element {
    int l;
    int k;
    int ind;
};
int a[MAXN];
bool ans[MAXN];
vector <Element> que[MAXN];
stack <int> st;
int tree[4*MAXN];
void update(int node, int l, int r, int qind, int ch) {
    if (qind>r || qind<l) return;
    if (l==r) {
        tree[node]=ch;
        return;
    }
    int mid=(l+r)/2;
    update(node*2,l,mid,qind,ch);
    update(node*2+1,mid+1,r,qind,ch);
    tree[node]=max(tree[node*2],tree[node*2+1]);
}
int query(int node, int l, int r, int ql, int qr) {
    if (ql>r || qr<l) return -1;
    if (l>=ql && r<=qr) return tree[node];
    int mid=(l+r)/2;
    return max(query(node*2,l,mid,ql,qr),query(node*2+1,mid+1,r,ql,qr));
}
int main () {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m;
    cin >> n >> m;
    for (int i=1;i<=n;i++) cin >> a[i];
    int l, r, k;
    for (int i=0;i<m;i++) {
        cin >> l >> r >> k;
        que[r].push_back({l,k,i});
    }
    for (int i=1;i<=n;i++) {
        while (!st.empty() && a[i]>=a[st.top()]) st.pop();
        if (!st.empty()) update(1,1,n,st.top(),a[i]+a[st.top()]);
        st.push(i);
        for (auto cur:que[i]) {
            ans[cur.ind]=(query(1,1,n,cur.l,i)<=cur.k);
        }
    }
    for (int i=0;i<m;i++) cout << ans[i] << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 26968 KB Output is correct
2 Correct 5 ms 26972 KB Output is correct
3 Correct 5 ms 26972 KB Output is correct
4 Correct 6 ms 27144 KB Output is correct
5 Correct 5 ms 26972 KB Output is correct
6 Correct 6 ms 26972 KB Output is correct
7 Correct 5 ms 27152 KB Output is correct
8 Correct 5 ms 26972 KB Output is correct
9 Correct 6 ms 26972 KB Output is correct
10 Correct 5 ms 27168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 26968 KB Output is correct
2 Correct 5 ms 26972 KB Output is correct
3 Correct 5 ms 26972 KB Output is correct
4 Correct 6 ms 27144 KB Output is correct
5 Correct 5 ms 26972 KB Output is correct
6 Correct 6 ms 26972 KB Output is correct
7 Correct 5 ms 27152 KB Output is correct
8 Correct 5 ms 26972 KB Output is correct
9 Correct 6 ms 26972 KB Output is correct
10 Correct 5 ms 27168 KB Output is correct
11 Correct 7 ms 27228 KB Output is correct
12 Correct 7 ms 27228 KB Output is correct
13 Correct 8 ms 27480 KB Output is correct
14 Correct 9 ms 27484 KB Output is correct
15 Correct 10 ms 27228 KB Output is correct
16 Correct 9 ms 27228 KB Output is correct
17 Correct 8 ms 27228 KB Output is correct
18 Correct 8 ms 27228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1028 ms 93684 KB Output is correct
2 Correct 1024 ms 94572 KB Output is correct
3 Correct 1024 ms 94544 KB Output is correct
4 Correct 1028 ms 94964 KB Output is correct
5 Correct 877 ms 86228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 33616 KB Output is correct
2 Correct 76 ms 33248 KB Output is correct
3 Correct 64 ms 31136 KB Output is correct
4 Correct 65 ms 31200 KB Output is correct
5 Correct 65 ms 31228 KB Output is correct
6 Correct 54 ms 32960 KB Output is correct
7 Correct 53 ms 32852 KB Output is correct
8 Correct 61 ms 30988 KB Output is correct
9 Correct 32 ms 29972 KB Output is correct
10 Correct 61 ms 30984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 26968 KB Output is correct
2 Correct 5 ms 26972 KB Output is correct
3 Correct 5 ms 26972 KB Output is correct
4 Correct 6 ms 27144 KB Output is correct
5 Correct 5 ms 26972 KB Output is correct
6 Correct 6 ms 26972 KB Output is correct
7 Correct 5 ms 27152 KB Output is correct
8 Correct 5 ms 26972 KB Output is correct
9 Correct 6 ms 26972 KB Output is correct
10 Correct 5 ms 27168 KB Output is correct
11 Correct 7 ms 27228 KB Output is correct
12 Correct 7 ms 27228 KB Output is correct
13 Correct 8 ms 27480 KB Output is correct
14 Correct 9 ms 27484 KB Output is correct
15 Correct 10 ms 27228 KB Output is correct
16 Correct 9 ms 27228 KB Output is correct
17 Correct 8 ms 27228 KB Output is correct
18 Correct 8 ms 27228 KB Output is correct
19 Correct 174 ms 40532 KB Output is correct
20 Correct 176 ms 40432 KB Output is correct
21 Correct 154 ms 39760 KB Output is correct
22 Correct 155 ms 39760 KB Output is correct
23 Correct 156 ms 39760 KB Output is correct
24 Correct 120 ms 37392 KB Output is correct
25 Correct 121 ms 37360 KB Output is correct
26 Correct 136 ms 37892 KB Output is correct
27 Correct 133 ms 37644 KB Output is correct
28 Correct 136 ms 37968 KB Output is correct
29 Correct 151 ms 38228 KB Output is correct
30 Correct 142 ms 38224 KB Output is correct
31 Correct 142 ms 38228 KB Output is correct
32 Correct 148 ms 38224 KB Output is correct
33 Correct 142 ms 38228 KB Output is correct
34 Correct 113 ms 39000 KB Output is correct
35 Correct 113 ms 38996 KB Output is correct
36 Correct 118 ms 39180 KB Output is correct
37 Correct 112 ms 38736 KB Output is correct
38 Correct 116 ms 38996 KB Output is correct
39 Correct 139 ms 37352 KB Output is correct
40 Correct 99 ms 35584 KB Output is correct
41 Correct 125 ms 36336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 26968 KB Output is correct
2 Correct 5 ms 26972 KB Output is correct
3 Correct 5 ms 26972 KB Output is correct
4 Correct 6 ms 27144 KB Output is correct
5 Correct 5 ms 26972 KB Output is correct
6 Correct 6 ms 26972 KB Output is correct
7 Correct 5 ms 27152 KB Output is correct
8 Correct 5 ms 26972 KB Output is correct
9 Correct 6 ms 26972 KB Output is correct
10 Correct 5 ms 27168 KB Output is correct
11 Correct 7 ms 27228 KB Output is correct
12 Correct 7 ms 27228 KB Output is correct
13 Correct 8 ms 27480 KB Output is correct
14 Correct 9 ms 27484 KB Output is correct
15 Correct 10 ms 27228 KB Output is correct
16 Correct 9 ms 27228 KB Output is correct
17 Correct 8 ms 27228 KB Output is correct
18 Correct 8 ms 27228 KB Output is correct
19 Correct 1028 ms 93684 KB Output is correct
20 Correct 1024 ms 94572 KB Output is correct
21 Correct 1024 ms 94544 KB Output is correct
22 Correct 1028 ms 94964 KB Output is correct
23 Correct 877 ms 86228 KB Output is correct
24 Correct 78 ms 33616 KB Output is correct
25 Correct 76 ms 33248 KB Output is correct
26 Correct 64 ms 31136 KB Output is correct
27 Correct 65 ms 31200 KB Output is correct
28 Correct 65 ms 31228 KB Output is correct
29 Correct 54 ms 32960 KB Output is correct
30 Correct 53 ms 32852 KB Output is correct
31 Correct 61 ms 30988 KB Output is correct
32 Correct 32 ms 29972 KB Output is correct
33 Correct 61 ms 30984 KB Output is correct
34 Correct 174 ms 40532 KB Output is correct
35 Correct 176 ms 40432 KB Output is correct
36 Correct 154 ms 39760 KB Output is correct
37 Correct 155 ms 39760 KB Output is correct
38 Correct 156 ms 39760 KB Output is correct
39 Correct 120 ms 37392 KB Output is correct
40 Correct 121 ms 37360 KB Output is correct
41 Correct 136 ms 37892 KB Output is correct
42 Correct 133 ms 37644 KB Output is correct
43 Correct 136 ms 37968 KB Output is correct
44 Correct 151 ms 38228 KB Output is correct
45 Correct 142 ms 38224 KB Output is correct
46 Correct 142 ms 38228 KB Output is correct
47 Correct 148 ms 38224 KB Output is correct
48 Correct 142 ms 38228 KB Output is correct
49 Correct 113 ms 39000 KB Output is correct
50 Correct 113 ms 38996 KB Output is correct
51 Correct 118 ms 39180 KB Output is correct
52 Correct 112 ms 38736 KB Output is correct
53 Correct 116 ms 38996 KB Output is correct
54 Correct 139 ms 37352 KB Output is correct
55 Correct 99 ms 35584 KB Output is correct
56 Correct 125 ms 36336 KB Output is correct
57 Correct 1040 ms 94724 KB Output is correct
58 Correct 1031 ms 94692 KB Output is correct
59 Correct 950 ms 93552 KB Output is correct
60 Correct 939 ms 93476 KB Output is correct
61 Correct 947 ms 93360 KB Output is correct
62 Correct 950 ms 93268 KB Output is correct
63 Correct 619 ms 81748 KB Output is correct
64 Correct 613 ms 81748 KB Output is correct
65 Correct 772 ms 84788 KB Output is correct
66 Correct 775 ms 84764 KB Output is correct
67 Correct 787 ms 85072 KB Output is correct
68 Correct 887 ms 86488 KB Output is correct
69 Correct 865 ms 86612 KB Output is correct
70 Correct 834 ms 86368 KB Output is correct
71 Correct 854 ms 86532 KB Output is correct
72 Correct 835 ms 86100 KB Output is correct
73 Correct 571 ms 81864 KB Output is correct
74 Correct 569 ms 82768 KB Output is correct
75 Correct 586 ms 81932 KB Output is correct
76 Correct 561 ms 81796 KB Output is correct
77 Correct 562 ms 81744 KB Output is correct
78 Correct 756 ms 81148 KB Output is correct
79 Correct 533 ms 70904 KB Output is correct
80 Correct 759 ms 76252 KB Output is correct