Submission #343948

# Submission time Handle Problem Language Result Execution time Memory
343948 2021-01-04T21:32:54 Z fixikmila Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1804 ms 102956 KB
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll>pll;
typedef long double ld;
ll bin_pow(ll a,ll b){
    if(b==0)return 1;
    if(b%2==0){
        ll t=bin_pow(a,b/2);
        return t*t%MOD;
    }
    else return a*bin_pow(a,b-1)%MOD;
}
struct cat{ll a,b,c;};
vector<cat>b[1000000];
ll a[1000000],c[1000000];
ll tree[4000001];
void update(ll l,ll x,ll v,ll tl,ll tr){
    if(tl==l&&tr==tl)tree[v]=max(tree[v],x);
    else if(tl>l||tr<l){
        return;
    }
    else{
        ll tm=(tl+tr)/2;
        update(l,x,2*v,tl,tm),update(l,x,2*v+1,tm+1,tr);
        tree[v]=max(tree[2*v+1],tree[2*v]);
    }
}
ll get_max(ll l,ll r,ll v,ll tl,ll tr){
    if(tl>=l&&tr<=r)return tree[v];
    else if(tl>r||tr<l)return LLONG_MIN;
    else{
        ll tm=(tl+tr)/2;
        return max(get_max(l,r,2*v,tl,tm),get_max(l,r,2*v+1,tm+1,tr));
    }
}
int main()
{
    //freopen("stones.in","r",stdin);
    //freopen("stones.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll t=1,n,m,k=0,sum=0,l=0,r=0,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<m;i++){
        cin>>l>>r>>k;
        l--,r--;
        cat f;
        f.a=l,f.b=k,f.c=i;
        b[r].push_back(f);
    }
    stack<ll>s;
    for(int i=0;i<n;i++){
        while(s.size()&&a[s.top()]<=a[i])s.pop();
        if(s.size()){
            ll j=s.top();
            update(j,a[i]+a[j],1,0,n-1);
        }
        s.push(i);
        for(auto u : b[i]){
            l=u.a,k=u.b;
            ll nom=u.c;
            c[nom]=get_max(l,n-1,1,0,n-1)<=k?1:0;
        }
    }
    for(int i=0;i<m;i++)cout<<c[i]<<"\n";
    return 0;
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:44:8: warning: unused variable 't' [-Wunused-variable]
   44 |     ll t=1,n,m,k=0,sum=0,l=0,r=0,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
      |        ^
sortbooks.cpp:44:20: warning: unused variable 'sum' [-Wunused-variable]
   44 |     ll t=1,n,m,k=0,sum=0,l=0,r=0,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
      |                    ^~~
sortbooks.cpp:44:34: warning: unused variable 'x' [-Wunused-variable]
   44 |     ll t=1,n,m,k=0,sum=0,l=0,r=0,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
      |                                  ^
sortbooks.cpp:44:38: warning: unused variable 'y' [-Wunused-variable]
   44 |     ll t=1,n,m,k=0,sum=0,l=0,r=0,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
      |                                      ^
sortbooks.cpp:44:42: warning: unused variable 'z' [-Wunused-variable]
   44 |     ll t=1,n,m,k=0,sum=0,l=0,r=0,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
      |                                          ^
sortbooks.cpp:44:46: warning: unused variable 'ans' [-Wunused-variable]
   44 |     ll t=1,n,m,k=0,sum=0,l=0,r=0,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
      |                                              ^~~
sortbooks.cpp:44:52: warning: unused variable 'mn' [-Wunused-variable]
   44 |     ll t=1,n,m,k=0,sum=0,l=0,r=0,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
      |                                                    ^~
sortbooks.cpp:44:65: warning: unused variable 'mx' [-Wunused-variable]
   44 |     ll t=1,n,m,k=0,sum=0,l=0,r=0,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
      |                                                                 ^~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 16 ms 23788 KB Output is correct
3 Correct 17 ms 23916 KB Output is correct
4 Correct 17 ms 23808 KB Output is correct
5 Correct 16 ms 23916 KB Output is correct
6 Correct 17 ms 23916 KB Output is correct
7 Correct 17 ms 23936 KB Output is correct
8 Correct 17 ms 23916 KB Output is correct
9 Correct 17 ms 23916 KB Output is correct
10 Correct 16 ms 23916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 16 ms 23788 KB Output is correct
3 Correct 17 ms 23916 KB Output is correct
4 Correct 17 ms 23808 KB Output is correct
5 Correct 16 ms 23916 KB Output is correct
6 Correct 17 ms 23916 KB Output is correct
7 Correct 17 ms 23936 KB Output is correct
8 Correct 17 ms 23916 KB Output is correct
9 Correct 17 ms 23916 KB Output is correct
10 Correct 16 ms 23916 KB Output is correct
11 Correct 19 ms 24044 KB Output is correct
12 Correct 20 ms 24172 KB Output is correct
13 Correct 20 ms 24300 KB Output is correct
14 Correct 21 ms 24428 KB Output is correct
15 Correct 23 ms 24428 KB Output is correct
16 Correct 20 ms 24428 KB Output is correct
17 Correct 19 ms 24172 KB Output is correct
18 Correct 20 ms 24172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1794 ms 90572 KB Output is correct
2 Correct 1804 ms 94828 KB Output is correct
3 Correct 1795 ms 102956 KB Output is correct
4 Correct 1787 ms 91016 KB Output is correct
5 Correct 1266 ms 74568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 31044 KB Output is correct
2 Correct 124 ms 33132 KB Output is correct
3 Correct 118 ms 30956 KB Output is correct
4 Correct 105 ms 30828 KB Output is correct
5 Correct 103 ms 30828 KB Output is correct
6 Correct 88 ms 31000 KB Output is correct
7 Correct 85 ms 30828 KB Output is correct
8 Correct 110 ms 30484 KB Output is correct
9 Correct 59 ms 29088 KB Output is correct
10 Correct 107 ms 30368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 16 ms 23788 KB Output is correct
3 Correct 17 ms 23916 KB Output is correct
4 Correct 17 ms 23808 KB Output is correct
5 Correct 16 ms 23916 KB Output is correct
6 Correct 17 ms 23916 KB Output is correct
7 Correct 17 ms 23936 KB Output is correct
8 Correct 17 ms 23916 KB Output is correct
9 Correct 17 ms 23916 KB Output is correct
10 Correct 16 ms 23916 KB Output is correct
11 Correct 19 ms 24044 KB Output is correct
12 Correct 20 ms 24172 KB Output is correct
13 Correct 20 ms 24300 KB Output is correct
14 Correct 21 ms 24428 KB Output is correct
15 Correct 23 ms 24428 KB Output is correct
16 Correct 20 ms 24428 KB Output is correct
17 Correct 19 ms 24172 KB Output is correct
18 Correct 20 ms 24172 KB Output is correct
19 Correct 311 ms 44396 KB Output is correct
20 Correct 315 ms 43756 KB Output is correct
21 Correct 258 ms 44252 KB Output is correct
22 Correct 259 ms 44268 KB Output is correct
23 Correct 270 ms 44396 KB Output is correct
24 Correct 193 ms 40684 KB Output is correct
25 Correct 193 ms 40428 KB Output is correct
26 Correct 214 ms 39916 KB Output is correct
27 Correct 227 ms 39968 KB Output is correct
28 Correct 224 ms 39916 KB Output is correct
29 Correct 233 ms 39660 KB Output is correct
30 Correct 235 ms 40044 KB Output is correct
31 Correct 228 ms 40044 KB Output is correct
32 Correct 241 ms 39916 KB Output is correct
33 Correct 232 ms 39916 KB Output is correct
34 Correct 176 ms 40152 KB Output is correct
35 Correct 176 ms 40172 KB Output is correct
36 Correct 168 ms 40172 KB Output is correct
37 Correct 168 ms 40044 KB Output is correct
38 Correct 176 ms 40172 KB Output is correct
39 Correct 216 ms 40116 KB Output is correct
40 Correct 170 ms 36892 KB Output is correct
41 Correct 228 ms 38044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 16 ms 23788 KB Output is correct
3 Correct 17 ms 23916 KB Output is correct
4 Correct 17 ms 23808 KB Output is correct
5 Correct 16 ms 23916 KB Output is correct
6 Correct 17 ms 23916 KB Output is correct
7 Correct 17 ms 23936 KB Output is correct
8 Correct 17 ms 23916 KB Output is correct
9 Correct 17 ms 23916 KB Output is correct
10 Correct 16 ms 23916 KB Output is correct
11 Correct 19 ms 24044 KB Output is correct
12 Correct 20 ms 24172 KB Output is correct
13 Correct 20 ms 24300 KB Output is correct
14 Correct 21 ms 24428 KB Output is correct
15 Correct 23 ms 24428 KB Output is correct
16 Correct 20 ms 24428 KB Output is correct
17 Correct 19 ms 24172 KB Output is correct
18 Correct 20 ms 24172 KB Output is correct
19 Correct 1794 ms 90572 KB Output is correct
20 Correct 1804 ms 94828 KB Output is correct
21 Correct 1795 ms 102956 KB Output is correct
22 Correct 1787 ms 91016 KB Output is correct
23 Correct 1266 ms 74568 KB Output is correct
24 Correct 133 ms 31044 KB Output is correct
25 Correct 124 ms 33132 KB Output is correct
26 Correct 118 ms 30956 KB Output is correct
27 Correct 105 ms 30828 KB Output is correct
28 Correct 103 ms 30828 KB Output is correct
29 Correct 88 ms 31000 KB Output is correct
30 Correct 85 ms 30828 KB Output is correct
31 Correct 110 ms 30484 KB Output is correct
32 Correct 59 ms 29088 KB Output is correct
33 Correct 107 ms 30368 KB Output is correct
34 Correct 311 ms 44396 KB Output is correct
35 Correct 315 ms 43756 KB Output is correct
36 Correct 258 ms 44252 KB Output is correct
37 Correct 259 ms 44268 KB Output is correct
38 Correct 270 ms 44396 KB Output is correct
39 Correct 193 ms 40684 KB Output is correct
40 Correct 193 ms 40428 KB Output is correct
41 Correct 214 ms 39916 KB Output is correct
42 Correct 227 ms 39968 KB Output is correct
43 Correct 224 ms 39916 KB Output is correct
44 Correct 233 ms 39660 KB Output is correct
45 Correct 235 ms 40044 KB Output is correct
46 Correct 228 ms 40044 KB Output is correct
47 Correct 241 ms 39916 KB Output is correct
48 Correct 232 ms 39916 KB Output is correct
49 Correct 176 ms 40152 KB Output is correct
50 Correct 176 ms 40172 KB Output is correct
51 Correct 168 ms 40172 KB Output is correct
52 Correct 168 ms 40044 KB Output is correct
53 Correct 176 ms 40172 KB Output is correct
54 Correct 216 ms 40116 KB Output is correct
55 Correct 170 ms 36892 KB Output is correct
56 Correct 228 ms 38044 KB Output is correct
57 Correct 1761 ms 100460 KB Output is correct
58 Correct 1793 ms 100016 KB Output is correct
59 Correct 1668 ms 99428 KB Output is correct
60 Correct 1661 ms 99436 KB Output is correct
61 Correct 1670 ms 99308 KB Output is correct
62 Correct 1675 ms 99408 KB Output is correct
63 Correct 965 ms 86764 KB Output is correct
64 Correct 973 ms 87020 KB Output is correct
65 Correct 1209 ms 82812 KB Output is correct
66 Correct 1220 ms 82788 KB Output is correct
67 Correct 1219 ms 82892 KB Output is correct
68 Correct 1252 ms 83580 KB Output is correct
69 Correct 1246 ms 83692 KB Output is correct
70 Correct 1239 ms 83692 KB Output is correct
71 Correct 1238 ms 83692 KB Output is correct
72 Correct 1250 ms 83652 KB Output is correct
73 Correct 819 ms 82156 KB Output is correct
74 Correct 868 ms 82284 KB Output is correct
75 Correct 854 ms 82284 KB Output is correct
76 Correct 830 ms 82924 KB Output is correct
77 Correct 835 ms 82156 KB Output is correct
78 Correct 1172 ms 83984 KB Output is correct
79 Correct 831 ms 66176 KB Output is correct
80 Correct 1229 ms 83296 KB Output is correct