Submission #877359

# Submission time Handle Problem Language Result Execution time Memory
877359 2023-11-23T07:48:39 Z TahirAliyev Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
2293 ms 95068 KB
#include <bits/stdc++.h>
#define ll unsigned long long
#define pii pair<ll, int>
using namespace std;

const int MAX = (1 << 20);
int tree[MAX * 2];

int ask(int ql, int qr, int node = 1, int l = 1, int r = MAX){
    if(ql > r || qr < l) return 0;
    if(ql <= l && r <= qr) return tree[node];
    int mid = (l + r) / 2;
    return max(ask(ql, qr, node * 2, l, mid), ask(ql, qr, node * 2 + 1, mid + 1, r));
}

void update(int pos, int val, int node = 1, int l = 1, int r = MAX){
    if(l == r){
        tree[node] = val;
        return;
    }
    int mid = (l + r) / 2;
    if(pos <= mid){
        update(pos, val, node * 2, l, mid);
    }
    else{
        update(pos, val, node * 2 + 1, mid + 1, r);
    }
    tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
}

int n, m;
vector<array<int, 3>> quer[MAX];    
bool ans[MAX];
int arr[MAX];

int main(){
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
    }
    for (int i = 0; i < m; i++)
    {
        int l, r, k; cin >> l >> r >> k;
        quer[r].push_back({l, k, i});
    }
    stack<pii> st;
    for (int i = 1; i <= n; i++)
    {
        while(!st.empty() && st.top().first <= arr[i]){
            st.pop();
        }
        if(st.size()){
            update(st.top().second, arr[st.top().second] + arr[i]);
        }
        st.push({arr[i], i});
        for(auto& q:quer[i]){
            ans[q[2]] = ask(q[0], i) <= q[1];
        }
    }
    
    for (int i = 0; i < m; i++)
    {
        cout << ans[i] << '\n';
    }
    
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:50:45: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'int' [-Wsign-compare]
   50 |         while(!st.empty() && st.top().first <= arr[i]){
      |                              ~~~~~~~~~~~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33116 KB Output is correct
2 Correct 6 ms 29144 KB Output is correct
3 Correct 7 ms 33112 KB Output is correct
4 Correct 7 ms 33116 KB Output is correct
5 Correct 7 ms 33112 KB Output is correct
6 Correct 8 ms 33284 KB Output is correct
7 Correct 7 ms 33116 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 7 ms 29016 KB Output is correct
10 Correct 7 ms 29020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33116 KB Output is correct
2 Correct 6 ms 29144 KB Output is correct
3 Correct 7 ms 33112 KB Output is correct
4 Correct 7 ms 33116 KB Output is correct
5 Correct 7 ms 33112 KB Output is correct
6 Correct 8 ms 33284 KB Output is correct
7 Correct 7 ms 33116 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 7 ms 29016 KB Output is correct
10 Correct 7 ms 29020 KB Output is correct
11 Correct 11 ms 33112 KB Output is correct
12 Correct 11 ms 33116 KB Output is correct
13 Correct 12 ms 33372 KB Output is correct
14 Correct 15 ms 33280 KB Output is correct
15 Correct 15 ms 33368 KB Output is correct
16 Correct 11 ms 29232 KB Output is correct
17 Correct 11 ms 29316 KB Output is correct
18 Correct 11 ms 29276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1868 ms 61672 KB Output is correct
2 Correct 1932 ms 61696 KB Output is correct
3 Correct 1877 ms 62112 KB Output is correct
4 Correct 1855 ms 61680 KB Output is correct
5 Correct 1751 ms 55152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 137 ms 37604 KB Output is correct
2 Correct 129 ms 37456 KB Output is correct
3 Correct 123 ms 33620 KB Output is correct
4 Correct 124 ms 33432 KB Output is correct
5 Correct 125 ms 33620 KB Output is correct
6 Correct 110 ms 37288 KB Output is correct
7 Correct 113 ms 37204 KB Output is correct
8 Correct 130 ms 33552 KB Output is correct
9 Correct 79 ms 30724 KB Output is correct
10 Correct 115 ms 33352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33116 KB Output is correct
2 Correct 6 ms 29144 KB Output is correct
3 Correct 7 ms 33112 KB Output is correct
4 Correct 7 ms 33116 KB Output is correct
5 Correct 7 ms 33112 KB Output is correct
6 Correct 8 ms 33284 KB Output is correct
7 Correct 7 ms 33116 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 7 ms 29016 KB Output is correct
10 Correct 7 ms 29020 KB Output is correct
11 Correct 11 ms 33112 KB Output is correct
12 Correct 11 ms 33116 KB Output is correct
13 Correct 12 ms 33372 KB Output is correct
14 Correct 15 ms 33280 KB Output is correct
15 Correct 15 ms 33368 KB Output is correct
16 Correct 11 ms 29232 KB Output is correct
17 Correct 11 ms 29316 KB Output is correct
18 Correct 11 ms 29276 KB Output is correct
19 Correct 372 ms 40016 KB Output is correct
20 Correct 344 ms 46972 KB Output is correct
21 Correct 324 ms 45904 KB Output is correct
22 Correct 325 ms 46076 KB Output is correct
23 Correct 322 ms 45996 KB Output is correct
24 Correct 292 ms 41720 KB Output is correct
25 Correct 294 ms 41812 KB Output is correct
26 Correct 310 ms 42068 KB Output is correct
27 Correct 338 ms 41976 KB Output is correct
28 Correct 320 ms 42240 KB Output is correct
29 Correct 325 ms 42620 KB Output is correct
30 Correct 334 ms 42580 KB Output is correct
31 Correct 316 ms 42368 KB Output is correct
32 Correct 326 ms 42400 KB Output is correct
33 Correct 319 ms 42448 KB Output is correct
34 Correct 349 ms 45396 KB Output is correct
35 Correct 286 ms 45228 KB Output is correct
36 Correct 287 ms 45304 KB Output is correct
37 Correct 277 ms 45136 KB Output is correct
38 Correct 312 ms 45572 KB Output is correct
39 Correct 281 ms 41084 KB Output is correct
40 Correct 227 ms 39724 KB Output is correct
41 Correct 263 ms 40196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33116 KB Output is correct
2 Correct 6 ms 29144 KB Output is correct
3 Correct 7 ms 33112 KB Output is correct
4 Correct 7 ms 33116 KB Output is correct
5 Correct 7 ms 33112 KB Output is correct
6 Correct 8 ms 33284 KB Output is correct
7 Correct 7 ms 33116 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 7 ms 29016 KB Output is correct
10 Correct 7 ms 29020 KB Output is correct
11 Correct 11 ms 33112 KB Output is correct
12 Correct 11 ms 33116 KB Output is correct
13 Correct 12 ms 33372 KB Output is correct
14 Correct 15 ms 33280 KB Output is correct
15 Correct 15 ms 33368 KB Output is correct
16 Correct 11 ms 29232 KB Output is correct
17 Correct 11 ms 29316 KB Output is correct
18 Correct 11 ms 29276 KB Output is correct
19 Correct 1868 ms 61672 KB Output is correct
20 Correct 1932 ms 61696 KB Output is correct
21 Correct 1877 ms 62112 KB Output is correct
22 Correct 1855 ms 61680 KB Output is correct
23 Correct 1751 ms 55152 KB Output is correct
24 Correct 137 ms 37604 KB Output is correct
25 Correct 129 ms 37456 KB Output is correct
26 Correct 123 ms 33620 KB Output is correct
27 Correct 124 ms 33432 KB Output is correct
28 Correct 125 ms 33620 KB Output is correct
29 Correct 110 ms 37288 KB Output is correct
30 Correct 113 ms 37204 KB Output is correct
31 Correct 130 ms 33552 KB Output is correct
32 Correct 79 ms 30724 KB Output is correct
33 Correct 115 ms 33352 KB Output is correct
34 Correct 372 ms 40016 KB Output is correct
35 Correct 344 ms 46972 KB Output is correct
36 Correct 324 ms 45904 KB Output is correct
37 Correct 325 ms 46076 KB Output is correct
38 Correct 322 ms 45996 KB Output is correct
39 Correct 292 ms 41720 KB Output is correct
40 Correct 294 ms 41812 KB Output is correct
41 Correct 310 ms 42068 KB Output is correct
42 Correct 338 ms 41976 KB Output is correct
43 Correct 320 ms 42240 KB Output is correct
44 Correct 325 ms 42620 KB Output is correct
45 Correct 334 ms 42580 KB Output is correct
46 Correct 316 ms 42368 KB Output is correct
47 Correct 326 ms 42400 KB Output is correct
48 Correct 319 ms 42448 KB Output is correct
49 Correct 349 ms 45396 KB Output is correct
50 Correct 286 ms 45228 KB Output is correct
51 Correct 287 ms 45304 KB Output is correct
52 Correct 277 ms 45136 KB Output is correct
53 Correct 312 ms 45572 KB Output is correct
54 Correct 281 ms 41084 KB Output is correct
55 Correct 227 ms 39724 KB Output is correct
56 Correct 263 ms 40196 KB Output is correct
57 Correct 1894 ms 95068 KB Output is correct
58 Correct 1857 ms 95060 KB Output is correct
59 Correct 2293 ms 93380 KB Output is correct
60 Correct 1810 ms 93596 KB Output is correct
61 Correct 1779 ms 93616 KB Output is correct
62 Correct 1806 ms 93584 KB Output is correct
63 Correct 1444 ms 83504 KB Output is correct
64 Correct 1455 ms 83348 KB Output is correct
65 Correct 1731 ms 86700 KB Output is correct
66 Correct 1740 ms 86288 KB Output is correct
67 Correct 1708 ms 86684 KB Output is correct
68 Correct 1789 ms 88180 KB Output is correct
69 Correct 1781 ms 88360 KB Output is correct
70 Correct 1800 ms 88032 KB Output is correct
71 Correct 1764 ms 87924 KB Output is correct
72 Correct 1761 ms 87824 KB Output is correct
73 Correct 1402 ms 83456 KB Output is correct
74 Correct 1429 ms 84288 KB Output is correct
75 Correct 1377 ms 83096 KB Output is correct
76 Correct 1386 ms 83512 KB Output is correct
77 Correct 1388 ms 83136 KB Output is correct
78 Correct 1525 ms 82428 KB Output is correct
79 Correct 1198 ms 73204 KB Output is correct
80 Correct 1438 ms 78880 KB Output is correct