Submission #532508

# Submission time Handle Problem Language Result Execution time Memory
532508 2022-03-03T03:40:30 Z dannyboy20031204 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1112 ms 143428 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void db() {cout << '\n';}
template <typename T, typename ...U> void db(T a, U ...b){
    cout << a << ' ', db(b...);
}
const int N = 1e6 + 1;
int pre[N];
void add(int pos, int val){
    for (int i = pos; i < N; i += i & -i) pre[i] = max(pre[i], val);
}
int query(int pos){
    int ans = 0;
    for (int i = pos; i; i -= i & -i) ans = max(ans, pre[i]);
    return ans;
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0);
    int n, m;
    cin >> n >> m;
    int a[n + 1], l[m], r[m], x[m], ans[m];
    vector<int> s, v[n + 1], q[n + 1];
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        while (!s.empty() and a[s.back()] <= a[i]) s.pop_back();
        if (!s.empty()) v[s.back()].push_back(i);
        s.push_back(i);
    }
    for (int i = 0; i < m; i++){
        cin >> l[i] >> r[i] >> x[i];
        q[l[i]].push_back(i);
    }
    for (int i = n; i > 0; i--){
        for (int j : v[i]){
            add(j, a[i] + a[j]);
        }
        for (int j : q[i]){
            ans[j] = query(r[j]) <= x[j] ? 1 : 0;
        }
    }
    for (int i : ans) db(i);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 324 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 324 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 588 KB Output is correct
12 Correct 3 ms 844 KB Output is correct
13 Correct 3 ms 844 KB Output is correct
14 Correct 4 ms 972 KB Output is correct
15 Correct 4 ms 972 KB Output is correct
16 Correct 4 ms 888 KB Output is correct
17 Correct 2 ms 828 KB Output is correct
18 Correct 3 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1026 ms 139852 KB Output is correct
2 Correct 1039 ms 130748 KB Output is correct
3 Correct 1040 ms 135780 KB Output is correct
4 Correct 1112 ms 124140 KB Output is correct
5 Correct 1033 ms 111392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 13252 KB Output is correct
2 Correct 68 ms 12236 KB Output is correct
3 Correct 57 ms 10820 KB Output is correct
4 Correct 54 ms 11040 KB Output is correct
5 Correct 57 ms 11208 KB Output is correct
6 Correct 44 ms 9796 KB Output is correct
7 Correct 45 ms 9668 KB Output is correct
8 Correct 57 ms 10956 KB Output is correct
9 Correct 32 ms 4068 KB Output is correct
10 Correct 56 ms 10672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 324 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 588 KB Output is correct
12 Correct 3 ms 844 KB Output is correct
13 Correct 3 ms 844 KB Output is correct
14 Correct 4 ms 972 KB Output is correct
15 Correct 4 ms 972 KB Output is correct
16 Correct 4 ms 888 KB Output is correct
17 Correct 2 ms 828 KB Output is correct
18 Correct 3 ms 844 KB Output is correct
19 Correct 180 ms 28840 KB Output is correct
20 Correct 177 ms 28736 KB Output is correct
21 Correct 144 ms 26304 KB Output is correct
22 Correct 146 ms 26248 KB Output is correct
23 Correct 141 ms 26192 KB Output is correct
24 Correct 112 ms 21924 KB Output is correct
25 Correct 112 ms 22040 KB Output is correct
26 Correct 141 ms 22940 KB Output is correct
27 Correct 129 ms 22996 KB Output is correct
28 Correct 135 ms 23444 KB Output is correct
29 Correct 155 ms 24772 KB Output is correct
30 Correct 149 ms 24688 KB Output is correct
31 Correct 141 ms 24644 KB Output is correct
32 Correct 152 ms 24600 KB Output is correct
33 Correct 148 ms 24616 KB Output is correct
34 Correct 109 ms 21524 KB Output is correct
35 Correct 106 ms 21580 KB Output is correct
36 Correct 100 ms 21500 KB Output is correct
37 Correct 101 ms 21344 KB Output is correct
38 Correct 108 ms 21512 KB Output is correct
39 Correct 129 ms 23292 KB Output is correct
40 Correct 104 ms 17600 KB Output is correct
41 Correct 115 ms 22640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 324 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 588 KB Output is correct
12 Correct 3 ms 844 KB Output is correct
13 Correct 3 ms 844 KB Output is correct
14 Correct 4 ms 972 KB Output is correct
15 Correct 4 ms 972 KB Output is correct
16 Correct 4 ms 888 KB Output is correct
17 Correct 2 ms 828 KB Output is correct
18 Correct 3 ms 844 KB Output is correct
19 Correct 1026 ms 139852 KB Output is correct
20 Correct 1039 ms 130748 KB Output is correct
21 Correct 1040 ms 135780 KB Output is correct
22 Correct 1112 ms 124140 KB Output is correct
23 Correct 1033 ms 111392 KB Output is correct
24 Correct 71 ms 13252 KB Output is correct
25 Correct 68 ms 12236 KB Output is correct
26 Correct 57 ms 10820 KB Output is correct
27 Correct 54 ms 11040 KB Output is correct
28 Correct 57 ms 11208 KB Output is correct
29 Correct 44 ms 9796 KB Output is correct
30 Correct 45 ms 9668 KB Output is correct
31 Correct 57 ms 10956 KB Output is correct
32 Correct 32 ms 4068 KB Output is correct
33 Correct 56 ms 10672 KB Output is correct
34 Correct 180 ms 28840 KB Output is correct
35 Correct 177 ms 28736 KB Output is correct
36 Correct 144 ms 26304 KB Output is correct
37 Correct 146 ms 26248 KB Output is correct
38 Correct 141 ms 26192 KB Output is correct
39 Correct 112 ms 21924 KB Output is correct
40 Correct 112 ms 22040 KB Output is correct
41 Correct 141 ms 22940 KB Output is correct
42 Correct 129 ms 22996 KB Output is correct
43 Correct 135 ms 23444 KB Output is correct
44 Correct 155 ms 24772 KB Output is correct
45 Correct 149 ms 24688 KB Output is correct
46 Correct 141 ms 24644 KB Output is correct
47 Correct 152 ms 24600 KB Output is correct
48 Correct 148 ms 24616 KB Output is correct
49 Correct 109 ms 21524 KB Output is correct
50 Correct 106 ms 21580 KB Output is correct
51 Correct 100 ms 21500 KB Output is correct
52 Correct 101 ms 21344 KB Output is correct
53 Correct 108 ms 21512 KB Output is correct
54 Correct 129 ms 23292 KB Output is correct
55 Correct 104 ms 17600 KB Output is correct
56 Correct 115 ms 22640 KB Output is correct
57 Correct 1020 ms 143236 KB Output is correct
58 Correct 1049 ms 143428 KB Output is correct
59 Correct 962 ms 137656 KB Output is correct
60 Correct 962 ms 137668 KB Output is correct
61 Correct 990 ms 137556 KB Output is correct
62 Correct 1006 ms 137860 KB Output is correct
63 Correct 613 ms 107088 KB Output is correct
64 Correct 619 ms 107112 KB Output is correct
65 Correct 849 ms 116588 KB Output is correct
66 Correct 843 ms 116588 KB Output is correct
67 Correct 872 ms 117164 KB Output is correct
68 Correct 911 ms 123164 KB Output is correct
69 Correct 904 ms 123184 KB Output is correct
70 Correct 892 ms 122312 KB Output is correct
71 Correct 904 ms 122320 KB Output is correct
72 Correct 918 ms 122264 KB Output is correct
73 Correct 571 ms 105472 KB Output is correct
74 Correct 579 ms 106564 KB Output is correct
75 Correct 585 ms 105548 KB Output is correct
76 Correct 565 ms 105420 KB Output is correct
77 Correct 573 ms 105656 KB Output is correct
78 Correct 774 ms 116432 KB Output is correct
79 Correct 574 ms 79480 KB Output is correct
80 Correct 759 ms 112736 KB Output is correct