Submission #686692

# Submission time Handle Problem Language Result Execution time Memory
686692 2023-01-25T18:51:24 Z speedyArda Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1426 ms 109188 KB
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const ll MAXN = 1e6 + 5;

ll seg[MAXN * 4];
ll w[MAXN], ans[MAXN];
void update(ll v, ll tl, ll tr, ll pos, ll val)
{

    if(tl == tr)
    {
        seg[v] = max(seg[v], val);
        return;
    }
    ll tm = (tl + tr) / 2;
        
    if(pos <= tm)
        update(2 * v, tl, tm, pos, val);
    else
        update(2 * v + 1, tm + 1, tr, pos, val);
    seg[v] = max(seg[v * 2], seg[v * 2 + 1]);

}

ll get(ll v, ll tl, ll tr, ll l, ll r)
{
    if(l > r)
        return 0;
    if(l == tl && r == tr)
    {
        return seg[v];
    }
    ll tm = (tl + tr) / 2;

    return max(get(2 * v, tl, tm, l, min(r, tm)), get(2 * v + 1, tm + 1, tr, max(tm + 1, l), r));
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, m;
    cin >> n >> m;
    for(ll i = 1; i <= n; i++)
        cin >> w[i];
    vector< vector < pair<pair<ll, ll>, ll> > > q(n+5);

    for(ll i = 1; i <= m; i++)
    {
        ll l, r, k;
        cin >> l >> r >> k;
        q[l].push_back({{r, k}, i});
    }
    vector<ll> curr;
    for(ll i = n; i >= 1; i--)
    {
        while(!curr.empty() && w[curr.back()] <= w[i])
        {
            if(w[curr.back()] != w[i])
                update(1, 1, n, curr.back(), w[curr.back()] + w[i]);
            curr.pop_back();
        }
        curr.push_back(i);
        for(pair< pair<ll, ll>, ll> elem : q[i])
        {
            ll temp = get(1, 1, n, i, elem.first.first);
            if(temp <= elem.first.second)
                ans[elem.second] = 1;
            else
                ans[elem.second] = 0;
        }
    }


    for(ll i = 1; i <= m; i++)
        cout << ans[i] << "\n";

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 5 ms 896 KB Output is correct
15 Correct 5 ms 980 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 3 ms 852 KB Output is correct
18 Correct 4 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1426 ms 92460 KB Output is correct
2 Correct 1348 ms 90448 KB Output is correct
3 Correct 1378 ms 92468 KB Output is correct
4 Correct 1376 ms 92316 KB Output is correct
5 Correct 1236 ms 83924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 11652 KB Output is correct
2 Correct 85 ms 12128 KB Output is correct
3 Correct 83 ms 9688 KB Output is correct
4 Correct 95 ms 9624 KB Output is correct
5 Correct 110 ms 9592 KB Output is correct
6 Correct 98 ms 9928 KB Output is correct
7 Correct 63 ms 9864 KB Output is correct
8 Correct 61 ms 9088 KB Output is correct
9 Correct 59 ms 5580 KB Output is correct
10 Correct 88 ms 9144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 5 ms 896 KB Output is correct
15 Correct 5 ms 980 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 3 ms 852 KB Output is correct
18 Correct 4 ms 724 KB Output is correct
19 Correct 249 ms 25676 KB Output is correct
20 Correct 290 ms 25708 KB Output is correct
21 Correct 225 ms 26564 KB Output is correct
22 Correct 275 ms 26624 KB Output is correct
23 Correct 206 ms 26604 KB Output is correct
24 Correct 191 ms 24256 KB Output is correct
25 Correct 171 ms 24252 KB Output is correct
26 Correct 193 ms 24004 KB Output is correct
27 Correct 209 ms 23880 KB Output is correct
28 Correct 194 ms 23608 KB Output is correct
29 Correct 203 ms 23384 KB Output is correct
30 Correct 225 ms 23328 KB Output is correct
31 Correct 209 ms 23340 KB Output is correct
32 Correct 200 ms 23392 KB Output is correct
33 Correct 222 ms 23400 KB Output is correct
34 Correct 169 ms 23260 KB Output is correct
35 Correct 151 ms 23212 KB Output is correct
36 Correct 155 ms 22940 KB Output is correct
37 Correct 150 ms 23064 KB Output is correct
38 Correct 149 ms 23168 KB Output is correct
39 Correct 171 ms 23924 KB Output is correct
40 Correct 150 ms 18816 KB Output is correct
41 Correct 142 ms 19304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 5 ms 896 KB Output is correct
15 Correct 5 ms 980 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 3 ms 852 KB Output is correct
18 Correct 4 ms 724 KB Output is correct
19 Correct 1426 ms 92460 KB Output is correct
20 Correct 1348 ms 90448 KB Output is correct
21 Correct 1378 ms 92468 KB Output is correct
22 Correct 1376 ms 92316 KB Output is correct
23 Correct 1236 ms 83924 KB Output is correct
24 Correct 98 ms 11652 KB Output is correct
25 Correct 85 ms 12128 KB Output is correct
26 Correct 83 ms 9688 KB Output is correct
27 Correct 95 ms 9624 KB Output is correct
28 Correct 110 ms 9592 KB Output is correct
29 Correct 98 ms 9928 KB Output is correct
30 Correct 63 ms 9864 KB Output is correct
31 Correct 61 ms 9088 KB Output is correct
32 Correct 59 ms 5580 KB Output is correct
33 Correct 88 ms 9144 KB Output is correct
34 Correct 249 ms 25676 KB Output is correct
35 Correct 290 ms 25708 KB Output is correct
36 Correct 225 ms 26564 KB Output is correct
37 Correct 275 ms 26624 KB Output is correct
38 Correct 206 ms 26604 KB Output is correct
39 Correct 191 ms 24256 KB Output is correct
40 Correct 171 ms 24252 KB Output is correct
41 Correct 193 ms 24004 KB Output is correct
42 Correct 209 ms 23880 KB Output is correct
43 Correct 194 ms 23608 KB Output is correct
44 Correct 203 ms 23384 KB Output is correct
45 Correct 225 ms 23328 KB Output is correct
46 Correct 209 ms 23340 KB Output is correct
47 Correct 200 ms 23392 KB Output is correct
48 Correct 222 ms 23400 KB Output is correct
49 Correct 169 ms 23260 KB Output is correct
50 Correct 151 ms 23212 KB Output is correct
51 Correct 155 ms 22940 KB Output is correct
52 Correct 150 ms 23064 KB Output is correct
53 Correct 149 ms 23168 KB Output is correct
54 Correct 171 ms 23924 KB Output is correct
55 Correct 150 ms 18816 KB Output is correct
56 Correct 142 ms 19304 KB Output is correct
57 Correct 1407 ms 105768 KB Output is correct
58 Correct 1411 ms 105808 KB Output is correct
59 Correct 1386 ms 107468 KB Output is correct
60 Correct 1378 ms 107424 KB Output is correct
61 Correct 1426 ms 101924 KB Output is correct
62 Correct 1395 ms 107464 KB Output is correct
63 Correct 1014 ms 98808 KB Output is correct
64 Correct 965 ms 99176 KB Output is correct
65 Correct 1203 ms 99700 KB Output is correct
66 Correct 1324 ms 99484 KB Output is correct
67 Correct 1219 ms 98784 KB Output is correct
68 Correct 1183 ms 97364 KB Output is correct
69 Correct 1195 ms 97608 KB Output is correct
70 Correct 1194 ms 97592 KB Output is correct
71 Correct 1188 ms 95180 KB Output is correct
72 Correct 1191 ms 98240 KB Output is correct
73 Correct 847 ms 96628 KB Output is correct
74 Correct 857 ms 97980 KB Output is correct
75 Correct 829 ms 96324 KB Output is correct
76 Correct 832 ms 106704 KB Output is correct
77 Correct 810 ms 103320 KB Output is correct
78 Correct 1008 ms 109188 KB Output is correct
79 Correct 703 ms 84824 KB Output is correct
80 Correct 875 ms 73880 KB Output is correct