Submission #1097614

# Submission time Handle Problem Language Result Execution time Memory
1097614 2024-10-07T16:09:40 Z 0pt1mus23 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
666 ms 116584 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ins insert      
#define pb push_back

#define putr(x) cout<<x<<endl;return; 
#define all(x) x.begin(),x.end()
#define endl '\n'
#define _ << " " <<

const int mod = 1e9+7,
            sze = 1e6 +23*2,    
            inf = 1e9,    
            L = 23 ;

int T[sze+23];
void upd(int node,int v){
    for(++node;node>0;node-=(node & -node)){
        T[node]=max(T[node],v);
    }
}
int qry(int node){
    int mx=0;
    for(++node;node<=sze; node +=(node & -node)){
        mx=max(mx,T[node]);
    }
    return mx;
}
void _0x0(){
    int n,q;
    cin>>n>>q;
    vector<int> arr(n);
    vector<int> ans(q,0);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    vector< vector< pair< pair<int,int>, int> > > event(n+10);
    int idx=0;
    while(q--){
        int l,r,k;
        cin>>l>>r>>k;
        --l;--r;
        event[r].pb( { {l,k}, idx++} );
    }
    vector<int> lst;
    for(int i=0;i<n;i++){
        while(!lst.empty() && arr[lst.back()]<=arr[i]){
            lst.pop_back();
        }
        if(!lst.empty()){
            upd(lst.back(), arr[lst.back()] + arr[i]);
        }
        lst.pb(i);
        for(auto v:event[i]){
            if(qry(v.first.first)<=v.first.second){
                ans[v.second]=1;
            }
        }
    }

    for(auto v:ans)cout<<v<<endl;
}
 
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int tt = 1;
    // cin>>tt;
    while(tt--){
        _0x0();
    }
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 360 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 360 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 856 KB Output is correct
13 Correct 2 ms 892 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 2 ms 736 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 666 ms 113232 KB Output is correct
2 Correct 635 ms 114540 KB Output is correct
3 Correct 603 ms 114512 KB Output is correct
4 Correct 626 ms 114516 KB Output is correct
5 Correct 586 ms 106852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 10580 KB Output is correct
2 Correct 38 ms 10576 KB Output is correct
3 Correct 37 ms 9796 KB Output is correct
4 Correct 49 ms 9812 KB Output is correct
5 Correct 38 ms 9812 KB Output is correct
6 Correct 33 ms 9560 KB Output is correct
7 Correct 37 ms 9680 KB Output is correct
8 Correct 37 ms 9600 KB Output is correct
9 Correct 25 ms 5648 KB Output is correct
10 Correct 36 ms 9492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 360 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 856 KB Output is correct
13 Correct 2 ms 892 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 2 ms 736 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 95 ms 23124 KB Output is correct
20 Correct 98 ms 23176 KB Output is correct
21 Correct 85 ms 23588 KB Output is correct
22 Correct 88 ms 23636 KB Output is correct
23 Correct 86 ms 23632 KB Output is correct
24 Correct 90 ms 21992 KB Output is correct
25 Correct 79 ms 22176 KB Output is correct
26 Correct 90 ms 21948 KB Output is correct
27 Correct 93 ms 21840 KB Output is correct
28 Correct 88 ms 21716 KB Output is correct
29 Correct 90 ms 21756 KB Output is correct
30 Correct 92 ms 21796 KB Output is correct
31 Correct 90 ms 21628 KB Output is correct
32 Correct 94 ms 21588 KB Output is correct
33 Correct 89 ms 21632 KB Output is correct
34 Correct 77 ms 21512 KB Output is correct
35 Correct 80 ms 21332 KB Output is correct
36 Correct 77 ms 21332 KB Output is correct
37 Correct 77 ms 21220 KB Output is correct
38 Correct 85 ms 21520 KB Output is correct
39 Correct 82 ms 20276 KB Output is correct
40 Correct 74 ms 16404 KB Output is correct
41 Correct 83 ms 21304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 360 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 856 KB Output is correct
13 Correct 2 ms 892 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 2 ms 736 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 666 ms 113232 KB Output is correct
20 Correct 635 ms 114540 KB Output is correct
21 Correct 603 ms 114512 KB Output is correct
22 Correct 626 ms 114516 KB Output is correct
23 Correct 586 ms 106852 KB Output is correct
24 Correct 41 ms 10580 KB Output is correct
25 Correct 38 ms 10576 KB Output is correct
26 Correct 37 ms 9796 KB Output is correct
27 Correct 49 ms 9812 KB Output is correct
28 Correct 38 ms 9812 KB Output is correct
29 Correct 33 ms 9560 KB Output is correct
30 Correct 37 ms 9680 KB Output is correct
31 Correct 37 ms 9600 KB Output is correct
32 Correct 25 ms 5648 KB Output is correct
33 Correct 36 ms 9492 KB Output is correct
34 Correct 95 ms 23124 KB Output is correct
35 Correct 98 ms 23176 KB Output is correct
36 Correct 85 ms 23588 KB Output is correct
37 Correct 88 ms 23636 KB Output is correct
38 Correct 86 ms 23632 KB Output is correct
39 Correct 90 ms 21992 KB Output is correct
40 Correct 79 ms 22176 KB Output is correct
41 Correct 90 ms 21948 KB Output is correct
42 Correct 93 ms 21840 KB Output is correct
43 Correct 88 ms 21716 KB Output is correct
44 Correct 90 ms 21756 KB Output is correct
45 Correct 92 ms 21796 KB Output is correct
46 Correct 90 ms 21628 KB Output is correct
47 Correct 94 ms 21588 KB Output is correct
48 Correct 89 ms 21632 KB Output is correct
49 Correct 77 ms 21512 KB Output is correct
50 Correct 80 ms 21332 KB Output is correct
51 Correct 77 ms 21332 KB Output is correct
52 Correct 77 ms 21220 KB Output is correct
53 Correct 85 ms 21520 KB Output is correct
54 Correct 82 ms 20276 KB Output is correct
55 Correct 74 ms 16404 KB Output is correct
56 Correct 83 ms 21304 KB Output is correct
57 Correct 600 ms 115536 KB Output is correct
58 Correct 593 ms 115556 KB Output is correct
59 Correct 551 ms 116188 KB Output is correct
60 Correct 542 ms 116196 KB Output is correct
61 Correct 574 ms 116584 KB Output is correct
62 Correct 542 ms 116296 KB Output is correct
63 Correct 388 ms 108624 KB Output is correct
64 Correct 376 ms 108624 KB Output is correct
65 Correct 477 ms 108480 KB Output is correct
66 Correct 485 ms 108424 KB Output is correct
67 Correct 461 ms 108516 KB Output is correct
68 Correct 531 ms 107604 KB Output is correct
69 Correct 541 ms 107604 KB Output is correct
70 Correct 600 ms 107860 KB Output is correct
71 Correct 547 ms 107860 KB Output is correct
72 Correct 551 ms 107720 KB Output is correct
73 Correct 382 ms 102472 KB Output is correct
74 Correct 401 ms 103776 KB Output is correct
75 Correct 376 ms 102228 KB Output is correct
76 Correct 389 ms 103016 KB Output is correct
77 Correct 369 ms 102624 KB Output is correct
78 Correct 523 ms 101620 KB Output is correct
79 Correct 431 ms 76884 KB Output is correct
80 Correct 537 ms 95312 KB Output is correct