Submission #480333

# Submission time Handle Problem Language Result Execution time Memory
480333 2021-10-15T16:58:51 Z Ronin13 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1482 ms 107416 KB
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pll pair<ll,ll>
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define epb emplace back
#define inf 1e9+1
#define linf 1e18+1
using namespace std;
const int NMAX=1e6+1;
int t[4*NMAX];

void update(int v,int l,int r,int pos,int val){
    if(l>pos||r<pos)return;
    if(l==r){
        t[v]=val;
        return;
    }
    int m=(l+r)/2;
    update(2*v,l,m,pos,val);update(2*v+1,m+1,r,pos,val);
    t[v]=max(t[2*v],t[2*v+1]);
}

int get(int v,int l,int r,int st,int fin){
    if(l>fin||r<st)return 0;
    if(l>=st&&r<=fin){
        return t[v];
    }
    int m=(l+r)/2;
    int x=get(2*v,l,m,st,fin);
    int y=get(2*v+1,m+1,r,st,fin);
    return max(x,y);
}

void solve(){
    int n;cin>>n;
    int m;cin>>m;
    vector<vector<int> >vec(n+1);
    int a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    stack<int>st;
    for(int i=1;i<=n;i++){
        while(!st.empty()){
            int v=st.top();
            if(a[v]<=a[i])st.pop();
            else break;
        }
        if(!st.empty()){
            int x=st.top();
            vec[x].pb(i);
        }
        st.push(i);
    }
    vector<pair<pii,pii> >q;
    for(int i=1;i<=m;i++){
        int l,r,x;cin>>l>>r>>x;
        q.pb({{-l,r},{x,i}});
    }
    sort(q.begin(),q.end());
    vector<int>ans(m+1);
    int ind=0;
    for(int i=n;i>=1;i--){
        for(int to:vec[i]){
            update(1,1,n,to,a[to]+a[i]);
        }
        while(ind<m){
            int l=-q[ind].f.f;
            if(l!=i)break;
            int r=q[ind].f.s;
            int val=q[ind].s.f;
            int idx=q[ind].s.s;
            int x=get(1,1,n,l,r);
            if(x>val)ans[idx]=0;
            else ans[idx]=1;
            ind++;
        }
    }
    for(int i=1;i<=m;i++){
        cout<<ans[i]<<"\n";
    }
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    //freopen("in.in","r",stdin);freopen("out.out","w",stdout);
    int test=1;//cin>>test;
    while(test--){
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 5 ms 588 KB Output is correct
13 Correct 5 ms 716 KB Output is correct
14 Correct 5 ms 756 KB Output is correct
15 Correct 6 ms 716 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 3 ms 588 KB Output is correct
18 Correct 4 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1427 ms 73764 KB Output is correct
2 Correct 1482 ms 74044 KB Output is correct
3 Correct 1375 ms 73768 KB Output is correct
4 Correct 1397 ms 73644 KB Output is correct
5 Correct 1006 ms 49300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 7764 KB Output is correct
2 Correct 115 ms 7804 KB Output is correct
3 Correct 88 ms 5172 KB Output is correct
4 Correct 88 ms 5192 KB Output is correct
5 Correct 84 ms 5148 KB Output is correct
6 Correct 85 ms 5440 KB Output is correct
7 Correct 80 ms 5420 KB Output is correct
8 Correct 84 ms 6248 KB Output is correct
9 Correct 52 ms 2540 KB Output is correct
10 Correct 93 ms 6024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 5 ms 588 KB Output is correct
13 Correct 5 ms 716 KB Output is correct
14 Correct 5 ms 756 KB Output is correct
15 Correct 6 ms 716 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 3 ms 588 KB Output is correct
18 Correct 4 ms 716 KB Output is correct
19 Correct 237 ms 15312 KB Output is correct
20 Correct 274 ms 15360 KB Output is correct
21 Correct 236 ms 15404 KB Output is correct
22 Correct 235 ms 15368 KB Output is correct
23 Correct 228 ms 15448 KB Output is correct
24 Correct 210 ms 10064 KB Output is correct
25 Correct 181 ms 10016 KB Output is correct
26 Correct 210 ms 10036 KB Output is correct
27 Correct 196 ms 10124 KB Output is correct
28 Correct 216 ms 10168 KB Output is correct
29 Correct 188 ms 10104 KB Output is correct
30 Correct 188 ms 10012 KB Output is correct
31 Correct 187 ms 10016 KB Output is correct
32 Correct 182 ms 10104 KB Output is correct
33 Correct 201 ms 10136 KB Output is correct
34 Correct 189 ms 10096 KB Output is correct
35 Correct 184 ms 10128 KB Output is correct
36 Correct 189 ms 10140 KB Output is correct
37 Correct 171 ms 10036 KB Output is correct
38 Correct 178 ms 10036 KB Output is correct
39 Correct 189 ms 11900 KB Output is correct
40 Correct 135 ms 8652 KB Output is correct
41 Correct 192 ms 12016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 5 ms 588 KB Output is correct
13 Correct 5 ms 716 KB Output is correct
14 Correct 5 ms 756 KB Output is correct
15 Correct 6 ms 716 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 3 ms 588 KB Output is correct
18 Correct 4 ms 716 KB Output is correct
19 Correct 1427 ms 73764 KB Output is correct
20 Correct 1482 ms 74044 KB Output is correct
21 Correct 1375 ms 73768 KB Output is correct
22 Correct 1397 ms 73644 KB Output is correct
23 Correct 1006 ms 49300 KB Output is correct
24 Correct 114 ms 7764 KB Output is correct
25 Correct 115 ms 7804 KB Output is correct
26 Correct 88 ms 5172 KB Output is correct
27 Correct 88 ms 5192 KB Output is correct
28 Correct 84 ms 5148 KB Output is correct
29 Correct 85 ms 5440 KB Output is correct
30 Correct 80 ms 5420 KB Output is correct
31 Correct 84 ms 6248 KB Output is correct
32 Correct 52 ms 2540 KB Output is correct
33 Correct 93 ms 6024 KB Output is correct
34 Correct 237 ms 15312 KB Output is correct
35 Correct 274 ms 15360 KB Output is correct
36 Correct 236 ms 15404 KB Output is correct
37 Correct 235 ms 15368 KB Output is correct
38 Correct 228 ms 15448 KB Output is correct
39 Correct 210 ms 10064 KB Output is correct
40 Correct 181 ms 10016 KB Output is correct
41 Correct 210 ms 10036 KB Output is correct
42 Correct 196 ms 10124 KB Output is correct
43 Correct 216 ms 10168 KB Output is correct
44 Correct 188 ms 10104 KB Output is correct
45 Correct 188 ms 10012 KB Output is correct
46 Correct 187 ms 10016 KB Output is correct
47 Correct 182 ms 10104 KB Output is correct
48 Correct 201 ms 10136 KB Output is correct
49 Correct 189 ms 10096 KB Output is correct
50 Correct 184 ms 10128 KB Output is correct
51 Correct 189 ms 10140 KB Output is correct
52 Correct 171 ms 10036 KB Output is correct
53 Correct 178 ms 10036 KB Output is correct
54 Correct 189 ms 11900 KB Output is correct
55 Correct 135 ms 8652 KB Output is correct
56 Correct 192 ms 12016 KB Output is correct
57 Correct 1411 ms 107256 KB Output is correct
58 Correct 1370 ms 107152 KB Output is correct
59 Correct 1321 ms 107164 KB Output is correct
60 Correct 1340 ms 107152 KB Output is correct
61 Correct 1370 ms 107308 KB Output is correct
62 Correct 1395 ms 107416 KB Output is correct
63 Correct 1026 ms 81036 KB Output is correct
64 Correct 1093 ms 80768 KB Output is correct
65 Correct 1081 ms 82664 KB Output is correct
66 Correct 1012 ms 82744 KB Output is correct
67 Correct 1043 ms 82788 KB Output is correct
68 Correct 1057 ms 82884 KB Output is correct
69 Correct 1057 ms 82788 KB Output is correct
70 Correct 1037 ms 82924 KB Output is correct
71 Correct 1051 ms 82884 KB Output is correct
72 Correct 1000 ms 82812 KB Output is correct
73 Correct 974 ms 79364 KB Output is correct
74 Correct 988 ms 80488 KB Output is correct
75 Correct 971 ms 79344 KB Output is correct
76 Correct 941 ms 79356 KB Output is correct
77 Correct 942 ms 79500 KB Output is correct
78 Correct 976 ms 84944 KB Output is correct
79 Correct 705 ms 60316 KB Output is correct
80 Correct 1041 ms 83596 KB Output is correct