Submission #168504

# Submission time Handle Problem Language Result Execution time Memory
168504 2019-12-13T11:37:47 Z IldarKA Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1432 ms 103864 KB
#include <bits/stdc++.h>

using namespace std;
bool ans[1000001];
int n, m, a[1000001], t[4000001];
vector < int > inv[1000001];
stack < int > s;
vector < pair < pair < int, int >, pair < int, int > > >  q;
void upd(int v, int tl, int tr, int pos, int val){
    if(tl == tr){
        t[v] = max(t[v], val);
        return;
    }
    int mid = (tl + tr) / 2;
    if(mid >= pos){
        upd(v + v, tl, mid, pos, val);
    }
    else{
        upd(v + 1 + v, mid + 1, tr, pos, val);
    }
    t[v] = max(t[v + v], t[v + 1 + v]);
}
int get(int v, int tl, int tr, int l, int r){
    if(l > r){
        return 0;
    }
    if(l == tl && tr == r){
        return t[v];
    }
    int mid = (tl + tr) / 2;
    return max(get(v + v, tl, mid, l, min(r, mid)), get(v + 1 + v, mid + 1, tr, max(l, mid + 1), r));
}
int main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
  	cout.tie(nullptr);
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = n; i >= 1; i--){
        while(!s.empty() && a[s.top()] < a[i]){
            inv[i].push_back(s.top());
            s.pop();
        }
        s.push(i);
    }
    for(int i = 1; i <= m; i++){
        int l, r, k;
        cin >> l >> r >> k;
        q.push_back({{l, r}, {k, i}});
    }
    sort(q.begin(), q.end());
    reverse(q.begin(), q.end());
    int l = n;
    for(int i = 0; i < m; i++){
        while(q[i].first.first <= l){
            for(auto to : inv[l]){
                upd(1, 1, n, to, a[to] + a[l]);
            }
            l--;
        }
        ans[q[i].second.second] = (get(1, 1, n, 1, q[i].first.second) <= q[i].second.first);
    }
    for(int i = 1; i <= m; i++){
        cout << ans[i] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 24 ms 23928 KB Output is correct
4 Correct 23 ms 23928 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 23 ms 23928 KB Output is correct
7 Correct 24 ms 23932 KB Output is correct
8 Correct 23 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 23 ms 23800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 24 ms 23928 KB Output is correct
4 Correct 23 ms 23928 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 23 ms 23928 KB Output is correct
7 Correct 24 ms 23932 KB Output is correct
8 Correct 23 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 23 ms 23800 KB Output is correct
11 Correct 25 ms 24056 KB Output is correct
12 Correct 26 ms 24184 KB Output is correct
13 Correct 27 ms 24312 KB Output is correct
14 Correct 28 ms 24312 KB Output is correct
15 Correct 28 ms 24352 KB Output is correct
16 Correct 28 ms 24312 KB Output is correct
17 Correct 26 ms 24256 KB Output is correct
18 Correct 27 ms 24312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1392 ms 73068 KB Output is correct
2 Correct 1395 ms 102624 KB Output is correct
3 Correct 1384 ms 102780 KB Output is correct
4 Correct 1377 ms 103220 KB Output is correct
5 Correct 1030 ms 83620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 29564 KB Output is correct
2 Correct 126 ms 29540 KB Output is correct
3 Correct 103 ms 27500 KB Output is correct
4 Correct 104 ms 27484 KB Output is correct
5 Correct 103 ms 27500 KB Output is correct
6 Correct 101 ms 27428 KB Output is correct
7 Correct 101 ms 27500 KB Output is correct
8 Correct 106 ms 28140 KB Output is correct
9 Correct 76 ms 26736 KB Output is correct
10 Correct 106 ms 28220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 24 ms 23928 KB Output is correct
4 Correct 23 ms 23928 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 23 ms 23928 KB Output is correct
7 Correct 24 ms 23932 KB Output is correct
8 Correct 23 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 23 ms 23800 KB Output is correct
11 Correct 25 ms 24056 KB Output is correct
12 Correct 26 ms 24184 KB Output is correct
13 Correct 27 ms 24312 KB Output is correct
14 Correct 28 ms 24312 KB Output is correct
15 Correct 28 ms 24352 KB Output is correct
16 Correct 28 ms 24312 KB Output is correct
17 Correct 26 ms 24256 KB Output is correct
18 Correct 27 ms 24312 KB Output is correct
19 Correct 271 ms 37360 KB Output is correct
20 Correct 269 ms 36336 KB Output is correct
21 Correct 262 ms 38208 KB Output is correct
22 Correct 263 ms 37724 KB Output is correct
23 Correct 259 ms 38128 KB Output is correct
24 Correct 208 ms 32744 KB Output is correct
25 Correct 207 ms 32212 KB Output is correct
26 Correct 218 ms 32304 KB Output is correct
27 Correct 213 ms 32592 KB Output is correct
28 Correct 211 ms 32744 KB Output is correct
29 Correct 218 ms 32760 KB Output is correct
30 Correct 215 ms 32224 KB Output is correct
31 Correct 214 ms 32484 KB Output is correct
32 Correct 215 ms 32232 KB Output is correct
33 Correct 214 ms 32232 KB Output is correct
34 Correct 203 ms 32488 KB Output is correct
35 Correct 205 ms 32572 KB Output is correct
36 Correct 206 ms 33048 KB Output is correct
37 Correct 201 ms 32872 KB Output is correct
38 Correct 203 ms 32872 KB Output is correct
39 Correct 211 ms 34268 KB Output is correct
40 Correct 171 ms 32492 KB Output is correct
41 Correct 206 ms 34332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 24 ms 23928 KB Output is correct
4 Correct 23 ms 23928 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 23 ms 23928 KB Output is correct
7 Correct 24 ms 23932 KB Output is correct
8 Correct 23 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 23 ms 23800 KB Output is correct
11 Correct 25 ms 24056 KB Output is correct
12 Correct 26 ms 24184 KB Output is correct
13 Correct 27 ms 24312 KB Output is correct
14 Correct 28 ms 24312 KB Output is correct
15 Correct 28 ms 24352 KB Output is correct
16 Correct 28 ms 24312 KB Output is correct
17 Correct 26 ms 24256 KB Output is correct
18 Correct 27 ms 24312 KB Output is correct
19 Correct 1392 ms 73068 KB Output is correct
20 Correct 1395 ms 102624 KB Output is correct
21 Correct 1384 ms 102780 KB Output is correct
22 Correct 1377 ms 103220 KB Output is correct
23 Correct 1030 ms 83620 KB Output is correct
24 Correct 129 ms 29564 KB Output is correct
25 Correct 126 ms 29540 KB Output is correct
26 Correct 103 ms 27500 KB Output is correct
27 Correct 104 ms 27484 KB Output is correct
28 Correct 103 ms 27500 KB Output is correct
29 Correct 101 ms 27428 KB Output is correct
30 Correct 101 ms 27500 KB Output is correct
31 Correct 106 ms 28140 KB Output is correct
32 Correct 76 ms 26736 KB Output is correct
33 Correct 106 ms 28220 KB Output is correct
34 Correct 271 ms 37360 KB Output is correct
35 Correct 269 ms 36336 KB Output is correct
36 Correct 262 ms 38208 KB Output is correct
37 Correct 263 ms 37724 KB Output is correct
38 Correct 259 ms 38128 KB Output is correct
39 Correct 208 ms 32744 KB Output is correct
40 Correct 207 ms 32212 KB Output is correct
41 Correct 218 ms 32304 KB Output is correct
42 Correct 213 ms 32592 KB Output is correct
43 Correct 211 ms 32744 KB Output is correct
44 Correct 218 ms 32760 KB Output is correct
45 Correct 215 ms 32224 KB Output is correct
46 Correct 214 ms 32484 KB Output is correct
47 Correct 215 ms 32232 KB Output is correct
48 Correct 214 ms 32232 KB Output is correct
49 Correct 203 ms 32488 KB Output is correct
50 Correct 205 ms 32572 KB Output is correct
51 Correct 206 ms 33048 KB Output is correct
52 Correct 201 ms 32872 KB Output is correct
53 Correct 203 ms 32872 KB Output is correct
54 Correct 211 ms 34268 KB Output is correct
55 Correct 171 ms 32492 KB Output is correct
56 Correct 206 ms 34332 KB Output is correct
57 Correct 1374 ms 102560 KB Output is correct
58 Correct 1369 ms 103864 KB Output is correct
59 Correct 1359 ms 103416 KB Output is correct
60 Correct 1333 ms 103324 KB Output is correct
61 Correct 1393 ms 102768 KB Output is correct
62 Correct 1432 ms 102804 KB Output is correct
63 Correct 1042 ms 82520 KB Output is correct
64 Correct 1006 ms 72220 KB Output is correct
65 Correct 1084 ms 80844 KB Output is correct
66 Correct 1055 ms 81500 KB Output is correct
67 Correct 1049 ms 81772 KB Output is correct
68 Correct 1052 ms 82932 KB Output is correct
69 Correct 1037 ms 82924 KB Output is correct
70 Correct 1037 ms 83236 KB Output is correct
71 Correct 1033 ms 83860 KB Output is correct
72 Correct 1049 ms 82888 KB Output is correct
73 Correct 987 ms 79640 KB Output is correct
74 Correct 993 ms 80844 KB Output is correct
75 Correct 971 ms 77476 KB Output is correct
76 Correct 983 ms 79760 KB Output is correct
77 Correct 979 ms 79968 KB Output is correct
78 Correct 1038 ms 84740 KB Output is correct
79 Correct 799 ms 69748 KB Output is correct
80 Correct 1068 ms 82316 KB Output is correct