Submission #1037071

# Submission time Handle Problem Language Result Execution time Memory
1037071 2024-07-28T02:40:29 Z adaawf Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
860 ms 137556 KB
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int t[4000005], res[1000005], a[1000005];
vector<int> g[1000005];
struct QUERY {
    int r, x, num;
};
vector<QUERY> v[1000005];
void update(int v, int tl, int tr, int l, int r, int x) {
    if (l > r) return;
    if (tl == l && tr == r) {
        t[v] = max(t[v], x);
        return;
    }
    t[v * 2] = max(t[v * 2], t[v]);
    t[v * 2 + 1] = max(t[v * 2 + 1], t[v]);
    int mid = (tl + tr) / 2;
    update(v * 2, tl, mid, l, min(r, mid), x);
    update(v * 2 + 1, mid + 1, tr, max(l, mid + 1), r, x);
}
int sum(int v, int tl, int tr, int x) {
    if (tl == tr) {
        return t[v];
    }
    t[v * 2] = max(t[v * 2], t[v]);
    t[v * 2 + 1] = max(t[v * 2 + 1], t[v]);
    int mid = (tl + tr) / 2;
    if (mid >= x) return sum(v * 2, tl, mid, x);
    return sum(v * 2 + 1, mid + 1, tr, x);
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, q;
    cin >> n >> q;
    stack<pair<int, int>> s;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        while (!s.empty() && (s.top()).first <= a[i]) {
            s.pop();
        }
        if (!s.empty()) {
            g[(s.top()).second].push_back(i);
        }
        s.push({a[i], i});
    }
    for (int i = 1; i <= q; i++) {
        int l, r, k;
        cin >> l >> r >> k;
        v[l].push_back({r, k, i});
    }
    for (int i = n; i >= 1; i--) {
        for (int w : g[i]) {
            update(1, 1, n, w, n, a[i] + a[w]);
        }
        for (auto w : v[i]) {
            if (sum(1, 1, n, w.r) <= w.x) {
                res[w.num] = 1;
            }
        }
    }
    for (int i = 1; i <= q; i++) cout << res[i] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 49752 KB Output is correct
2 Correct 8 ms 49756 KB Output is correct
3 Correct 8 ms 49752 KB Output is correct
4 Correct 8 ms 49876 KB Output is correct
5 Correct 8 ms 49756 KB Output is correct
6 Correct 8 ms 49756 KB Output is correct
7 Correct 8 ms 49900 KB Output is correct
8 Correct 9 ms 49756 KB Output is correct
9 Correct 8 ms 49756 KB Output is correct
10 Correct 8 ms 49852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 49752 KB Output is correct
2 Correct 8 ms 49756 KB Output is correct
3 Correct 8 ms 49752 KB Output is correct
4 Correct 8 ms 49876 KB Output is correct
5 Correct 8 ms 49756 KB Output is correct
6 Correct 8 ms 49756 KB Output is correct
7 Correct 8 ms 49900 KB Output is correct
8 Correct 9 ms 49756 KB Output is correct
9 Correct 8 ms 49756 KB Output is correct
10 Correct 8 ms 49852 KB Output is correct
11 Correct 10 ms 50008 KB Output is correct
12 Correct 10 ms 50072 KB Output is correct
13 Correct 10 ms 50012 KB Output is correct
14 Correct 11 ms 50268 KB Output is correct
15 Correct 12 ms 50268 KB Output is correct
16 Correct 10 ms 50012 KB Output is correct
17 Correct 10 ms 50012 KB Output is correct
18 Correct 11 ms 50084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 794 ms 134064 KB Output is correct
2 Correct 791 ms 134988 KB Output is correct
3 Correct 781 ms 134680 KB Output is correct
4 Correct 769 ms 134992 KB Output is correct
5 Correct 622 ms 120004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 56792 KB Output is correct
2 Correct 60 ms 56652 KB Output is correct
3 Correct 50 ms 54868 KB Output is correct
4 Correct 48 ms 55120 KB Output is correct
5 Correct 49 ms 55184 KB Output is correct
6 Correct 39 ms 51632 KB Output is correct
7 Correct 44 ms 51792 KB Output is correct
8 Correct 51 ms 54756 KB Output is correct
9 Correct 31 ms 52696 KB Output is correct
10 Correct 51 ms 54676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 49752 KB Output is correct
2 Correct 8 ms 49756 KB Output is correct
3 Correct 8 ms 49752 KB Output is correct
4 Correct 8 ms 49876 KB Output is correct
5 Correct 8 ms 49756 KB Output is correct
6 Correct 8 ms 49756 KB Output is correct
7 Correct 8 ms 49900 KB Output is correct
8 Correct 9 ms 49756 KB Output is correct
9 Correct 8 ms 49756 KB Output is correct
10 Correct 8 ms 49852 KB Output is correct
11 Correct 10 ms 50008 KB Output is correct
12 Correct 10 ms 50072 KB Output is correct
13 Correct 10 ms 50012 KB Output is correct
14 Correct 11 ms 50268 KB Output is correct
15 Correct 12 ms 50268 KB Output is correct
16 Correct 10 ms 50012 KB Output is correct
17 Correct 10 ms 50012 KB Output is correct
18 Correct 11 ms 50084 KB Output is correct
19 Correct 144 ms 70740 KB Output is correct
20 Correct 152 ms 70740 KB Output is correct
21 Correct 126 ms 69968 KB Output is correct
22 Correct 127 ms 69944 KB Output is correct
23 Correct 122 ms 69968 KB Output is correct
24 Correct 92 ms 64596 KB Output is correct
25 Correct 100 ms 64800 KB Output is correct
26 Correct 97 ms 65660 KB Output is correct
27 Correct 99 ms 65620 KB Output is correct
28 Correct 99 ms 65872 KB Output is correct
29 Correct 113 ms 67420 KB Output is correct
30 Correct 103 ms 67392 KB Output is correct
31 Correct 106 ms 67184 KB Output is correct
32 Correct 112 ms 67396 KB Output is correct
33 Correct 106 ms 67384 KB Output is correct
34 Correct 86 ms 63824 KB Output is correct
35 Correct 83 ms 63928 KB Output is correct
36 Correct 87 ms 63568 KB Output is correct
37 Correct 83 ms 63800 KB Output is correct
38 Correct 82 ms 63816 KB Output is correct
39 Correct 101 ms 66312 KB Output is correct
40 Correct 85 ms 63236 KB Output is correct
41 Correct 102 ms 65096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 49752 KB Output is correct
2 Correct 8 ms 49756 KB Output is correct
3 Correct 8 ms 49752 KB Output is correct
4 Correct 8 ms 49876 KB Output is correct
5 Correct 8 ms 49756 KB Output is correct
6 Correct 8 ms 49756 KB Output is correct
7 Correct 8 ms 49900 KB Output is correct
8 Correct 9 ms 49756 KB Output is correct
9 Correct 8 ms 49756 KB Output is correct
10 Correct 8 ms 49852 KB Output is correct
11 Correct 10 ms 50008 KB Output is correct
12 Correct 10 ms 50072 KB Output is correct
13 Correct 10 ms 50012 KB Output is correct
14 Correct 11 ms 50268 KB Output is correct
15 Correct 12 ms 50268 KB Output is correct
16 Correct 10 ms 50012 KB Output is correct
17 Correct 10 ms 50012 KB Output is correct
18 Correct 11 ms 50084 KB Output is correct
19 Correct 794 ms 134064 KB Output is correct
20 Correct 791 ms 134988 KB Output is correct
21 Correct 781 ms 134680 KB Output is correct
22 Correct 769 ms 134992 KB Output is correct
23 Correct 622 ms 120004 KB Output is correct
24 Correct 76 ms 56792 KB Output is correct
25 Correct 60 ms 56652 KB Output is correct
26 Correct 50 ms 54868 KB Output is correct
27 Correct 48 ms 55120 KB Output is correct
28 Correct 49 ms 55184 KB Output is correct
29 Correct 39 ms 51632 KB Output is correct
30 Correct 44 ms 51792 KB Output is correct
31 Correct 51 ms 54756 KB Output is correct
32 Correct 31 ms 52696 KB Output is correct
33 Correct 51 ms 54676 KB Output is correct
34 Correct 144 ms 70740 KB Output is correct
35 Correct 152 ms 70740 KB Output is correct
36 Correct 126 ms 69968 KB Output is correct
37 Correct 127 ms 69944 KB Output is correct
38 Correct 122 ms 69968 KB Output is correct
39 Correct 92 ms 64596 KB Output is correct
40 Correct 100 ms 64800 KB Output is correct
41 Correct 97 ms 65660 KB Output is correct
42 Correct 99 ms 65620 KB Output is correct
43 Correct 99 ms 65872 KB Output is correct
44 Correct 113 ms 67420 KB Output is correct
45 Correct 103 ms 67392 KB Output is correct
46 Correct 106 ms 67184 KB Output is correct
47 Correct 112 ms 67396 KB Output is correct
48 Correct 106 ms 67384 KB Output is correct
49 Correct 86 ms 63824 KB Output is correct
50 Correct 83 ms 63928 KB Output is correct
51 Correct 87 ms 63568 KB Output is correct
52 Correct 83 ms 63800 KB Output is correct
53 Correct 82 ms 63816 KB Output is correct
54 Correct 101 ms 66312 KB Output is correct
55 Correct 85 ms 63236 KB Output is correct
56 Correct 102 ms 65096 KB Output is correct
57 Correct 860 ms 137556 KB Output is correct
58 Correct 783 ms 137556 KB Output is correct
59 Correct 758 ms 135508 KB Output is correct
60 Correct 777 ms 135508 KB Output is correct
61 Correct 734 ms 135524 KB Output is correct
62 Correct 761 ms 135504 KB Output is correct
63 Correct 430 ms 105556 KB Output is correct
64 Correct 432 ms 105660 KB Output is correct
65 Correct 562 ms 115020 KB Output is correct
66 Correct 529 ms 115028 KB Output is correct
67 Correct 571 ms 115200 KB Output is correct
68 Correct 633 ms 121428 KB Output is correct
69 Correct 623 ms 121424 KB Output is correct
70 Correct 592 ms 120144 KB Output is correct
71 Correct 606 ms 120008 KB Output is correct
72 Correct 624 ms 120000 KB Output is correct
73 Correct 387 ms 103012 KB Output is correct
74 Correct 386 ms 103760 KB Output is correct
75 Correct 401 ms 103220 KB Output is correct
76 Correct 400 ms 102992 KB Output is correct
77 Correct 375 ms 102996 KB Output is correct
78 Correct 540 ms 116732 KB Output is correct
79 Correct 439 ms 100924 KB Output is correct
80 Correct 563 ms 111376 KB Output is correct