Submission #391509

# Submission time Handle Problem Language Result Execution time Memory
391509 2021-04-19T05:45:02 Z _eve Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1865 ms 104860 KB
#include <bits/stdc++.h>

#define ll long long

using namespace std;

const int N = (int)1e6 + 10;
const int mod = 1e9 + 7;
const ll inf = 1e17 + 10;

int n, q, a[N], ans[N];
struct Q{
    int l,k,id;
    Q() {};
    Q(int _l,int _k,int _id) : l(_l), k(_k), id(_id) {};
};
vector<Q> query[N];
ll t[N * 4];
void upd(int p,ll x,int u,int l,int r) {
    if(l == r) {
        t[u] = x;
        return;
    }
    int m = l + r >> 1;
    if(p <= m) upd(p,x,u << 1,l,m);
    else upd(p,x,u << 1 | 1,m + 1,r);
    t[u] = max(t[u << 1],t[u << 1 | 1]);
}
int get(int ql,int qr,int u,int l,int r) {
    if(ql > r || l > qr) return -1;
    if(ql <= l && r <= qr) return t[u];
    int m = l + r >> 1;
    return max(get(ql,qr,u<<1,l,m),get(ql,qr,u<<1|1,m+1,r));
}
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> n >> q;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= q; i++) {
        int l,r,k; 
        cin >> l >> r >> k;
        Q x = Q(l,k,i);
        query[r].push_back(x);
    }
    stack<int> s;
    for(int i = 1; i <= n; i++) {
        while(!s.empty() && a[s.top()] <= a[i]) s.pop();
        if(!s.empty()) {
            upd(s.top(),a[s.top()] + a[i],1,1,n);
        }
        for(Q x : query[i]) {
            ans[x.id] = (get(x.l,i,1,1,n) <= x.k); 
        }
        s.push(i);
    }
    for(int i = 1; i <= q; i++) cout << ans[i] << "\n";
}

Compilation message

sortbooks.cpp: In function 'void upd(int, long long int, int, int, int)':
sortbooks.cpp:24:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |     int m = l + r >> 1;
      |             ~~^~~
sortbooks.cpp: In function 'int get(int, int, int, int, int)':
sortbooks.cpp:32:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |     int m = l + r >> 1;
      |             ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Correct 16 ms 23812 KB Output is correct
4 Correct 16 ms 23756 KB Output is correct
5 Correct 16 ms 23832 KB Output is correct
6 Correct 16 ms 23828 KB Output is correct
7 Correct 16 ms 23800 KB Output is correct
8 Correct 16 ms 23756 KB Output is correct
9 Correct 15 ms 23760 KB Output is correct
10 Correct 16 ms 23776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Correct 16 ms 23812 KB Output is correct
4 Correct 16 ms 23756 KB Output is correct
5 Correct 16 ms 23832 KB Output is correct
6 Correct 16 ms 23828 KB Output is correct
7 Correct 16 ms 23800 KB Output is correct
8 Correct 16 ms 23756 KB Output is correct
9 Correct 15 ms 23760 KB Output is correct
10 Correct 16 ms 23776 KB Output is correct
11 Correct 20 ms 23852 KB Output is correct
12 Correct 18 ms 23972 KB Output is correct
13 Correct 21 ms 23964 KB Output is correct
14 Correct 21 ms 24044 KB Output is correct
15 Correct 22 ms 24012 KB Output is correct
16 Correct 19 ms 23988 KB Output is correct
17 Correct 18 ms 23940 KB Output is correct
18 Correct 20 ms 23884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1791 ms 71680 KB Output is correct
2 Correct 1865 ms 104652 KB Output is correct
3 Correct 1846 ms 104588 KB Output is correct
4 Correct 1817 ms 104700 KB Output is correct
5 Correct 1489 ms 88288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 29044 KB Output is correct
2 Correct 138 ms 28672 KB Output is correct
3 Correct 109 ms 26708 KB Output is correct
4 Correct 121 ms 26824 KB Output is correct
5 Correct 111 ms 26840 KB Output is correct
6 Correct 94 ms 26460 KB Output is correct
7 Correct 95 ms 26524 KB Output is correct
8 Correct 106 ms 26744 KB Output is correct
9 Correct 59 ms 25860 KB Output is correct
10 Correct 101 ms 26720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Correct 16 ms 23812 KB Output is correct
4 Correct 16 ms 23756 KB Output is correct
5 Correct 16 ms 23832 KB Output is correct
6 Correct 16 ms 23828 KB Output is correct
7 Correct 16 ms 23800 KB Output is correct
8 Correct 16 ms 23756 KB Output is correct
9 Correct 15 ms 23760 KB Output is correct
10 Correct 16 ms 23776 KB Output is correct
11 Correct 20 ms 23852 KB Output is correct
12 Correct 18 ms 23972 KB Output is correct
13 Correct 21 ms 23964 KB Output is correct
14 Correct 21 ms 24044 KB Output is correct
15 Correct 22 ms 24012 KB Output is correct
16 Correct 19 ms 23988 KB Output is correct
17 Correct 18 ms 23940 KB Output is correct
18 Correct 20 ms 23884 KB Output is correct
19 Correct 295 ms 34160 KB Output is correct
20 Correct 310 ms 34012 KB Output is correct
21 Correct 254 ms 33540 KB Output is correct
22 Correct 289 ms 33608 KB Output is correct
23 Correct 293 ms 33596 KB Output is correct
24 Correct 213 ms 29380 KB Output is correct
25 Correct 209 ms 29432 KB Output is correct
26 Correct 262 ms 29608 KB Output is correct
27 Correct 244 ms 29616 KB Output is correct
28 Correct 267 ms 29632 KB Output is correct
29 Correct 251 ms 30024 KB Output is correct
30 Correct 272 ms 29904 KB Output is correct
31 Correct 258 ms 29984 KB Output is correct
32 Correct 244 ms 29892 KB Output is correct
33 Correct 280 ms 29972 KB Output is correct
34 Correct 200 ms 29140 KB Output is correct
35 Correct 195 ms 29180 KB Output is correct
36 Correct 209 ms 29308 KB Output is correct
37 Correct 191 ms 29036 KB Output is correct
38 Correct 197 ms 29152 KB Output is correct
39 Correct 233 ms 31288 KB Output is correct
40 Correct 170 ms 29044 KB Output is correct
41 Correct 211 ms 29636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Correct 16 ms 23812 KB Output is correct
4 Correct 16 ms 23756 KB Output is correct
5 Correct 16 ms 23832 KB Output is correct
6 Correct 16 ms 23828 KB Output is correct
7 Correct 16 ms 23800 KB Output is correct
8 Correct 16 ms 23756 KB Output is correct
9 Correct 15 ms 23760 KB Output is correct
10 Correct 16 ms 23776 KB Output is correct
11 Correct 20 ms 23852 KB Output is correct
12 Correct 18 ms 23972 KB Output is correct
13 Correct 21 ms 23964 KB Output is correct
14 Correct 21 ms 24044 KB Output is correct
15 Correct 22 ms 24012 KB Output is correct
16 Correct 19 ms 23988 KB Output is correct
17 Correct 18 ms 23940 KB Output is correct
18 Correct 20 ms 23884 KB Output is correct
19 Correct 1791 ms 71680 KB Output is correct
20 Correct 1865 ms 104652 KB Output is correct
21 Correct 1846 ms 104588 KB Output is correct
22 Correct 1817 ms 104700 KB Output is correct
23 Correct 1489 ms 88288 KB Output is correct
24 Correct 140 ms 29044 KB Output is correct
25 Correct 138 ms 28672 KB Output is correct
26 Correct 109 ms 26708 KB Output is correct
27 Correct 121 ms 26824 KB Output is correct
28 Correct 111 ms 26840 KB Output is correct
29 Correct 94 ms 26460 KB Output is correct
30 Correct 95 ms 26524 KB Output is correct
31 Correct 106 ms 26744 KB Output is correct
32 Correct 59 ms 25860 KB Output is correct
33 Correct 101 ms 26720 KB Output is correct
34 Correct 295 ms 34160 KB Output is correct
35 Correct 310 ms 34012 KB Output is correct
36 Correct 254 ms 33540 KB Output is correct
37 Correct 289 ms 33608 KB Output is correct
38 Correct 293 ms 33596 KB Output is correct
39 Correct 213 ms 29380 KB Output is correct
40 Correct 209 ms 29432 KB Output is correct
41 Correct 262 ms 29608 KB Output is correct
42 Correct 244 ms 29616 KB Output is correct
43 Correct 267 ms 29632 KB Output is correct
44 Correct 251 ms 30024 KB Output is correct
45 Correct 272 ms 29904 KB Output is correct
46 Correct 258 ms 29984 KB Output is correct
47 Correct 244 ms 29892 KB Output is correct
48 Correct 280 ms 29972 KB Output is correct
49 Correct 200 ms 29140 KB Output is correct
50 Correct 195 ms 29180 KB Output is correct
51 Correct 209 ms 29308 KB Output is correct
52 Correct 191 ms 29036 KB Output is correct
53 Correct 197 ms 29152 KB Output is correct
54 Correct 233 ms 31288 KB Output is correct
55 Correct 170 ms 29044 KB Output is correct
56 Correct 211 ms 29636 KB Output is correct
57 Correct 1795 ms 104796 KB Output is correct
58 Correct 1827 ms 104860 KB Output is correct
59 Correct 1677 ms 103388 KB Output is correct
60 Correct 1714 ms 103480 KB Output is correct
61 Correct 1687 ms 103500 KB Output is correct
62 Correct 1709 ms 103400 KB Output is correct
63 Correct 1089 ms 83580 KB Output is correct
64 Correct 1094 ms 83736 KB Output is correct
65 Correct 1380 ms 86928 KB Output is correct
66 Correct 1362 ms 86804 KB Output is correct
67 Correct 1380 ms 86844 KB Output is correct
68 Correct 1419 ms 88648 KB Output is correct
69 Correct 1424 ms 88532 KB Output is correct
70 Correct 1400 ms 88096 KB Output is correct
71 Correct 1424 ms 88252 KB Output is correct
72 Correct 1416 ms 88100 KB Output is correct
73 Correct 951 ms 79532 KB Output is correct
74 Correct 975 ms 80760 KB Output is correct
75 Correct 957 ms 79832 KB Output is correct
76 Correct 952 ms 79772 KB Output is correct
77 Correct 944 ms 79532 KB Output is correct
78 Correct 1260 ms 86196 KB Output is correct
79 Correct 883 ms 71652 KB Output is correct
80 Correct 1225 ms 77868 KB Output is correct