Submission #409181

# Submission time Handle Problem Language Result Execution time Memory
409181 2021-05-20T10:04:49 Z Ronin13 Divide and conquer (IZhO14_divide) C++14
100 / 100
153 ms 14916 KB
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ull unsigned ll
#define pb push_back
#define epb emplace_back
using namespace std;

vector<ll>x(200001),d(200001);
vector<ll>g(200001);
vector<ll>t(800001,1e18+1);

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

int get(int v,int l,int r,ll val){
    if(l==r){
        return l;
    }
    int m=(l+r)/2;
    if(t[2*v]<=val)return get(2*v,l,m,val);
    if(t[2*v+1]<=val)return get(2*v+1,m+1,r,val);
    return -1;
}

void solve(){
    int n;cin>>n;
    vector<ll>pref(n+1);
    pref[0]=0;
    for(int i=1;i<=n;i++){
        cin>>x[i]>>g[i]>>d[i];
        d[i]+=d[i-1];
        pref[i]=pref[i-1]+g[i];
    }
    ll mx=0;
    for(int i=1;i<=n;i++){
        update(1,1,n,d[i-1]-x[i],i);
        int ind=get(1,1,n,d[i]-x[i]);

        mx=max(mx,pref[i]-pref[ind-1]);
    }
    cout<<mx;
}

int main(){
    solve();
}


# Verdict Execution time Memory Grader output
1 Correct 7 ms 11212 KB Output is correct
2 Correct 6 ms 11212 KB Output is correct
3 Correct 6 ms 11212 KB Output is correct
4 Correct 6 ms 11212 KB Output is correct
5 Correct 6 ms 11212 KB Output is correct
6 Correct 6 ms 11212 KB Output is correct
7 Correct 6 ms 11160 KB Output is correct
8 Correct 6 ms 11212 KB Output is correct
9 Correct 6 ms 11212 KB Output is correct
10 Correct 6 ms 11212 KB Output is correct
11 Correct 6 ms 11212 KB Output is correct
12 Correct 6 ms 11212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11212 KB Output is correct
2 Correct 6 ms 11212 KB Output is correct
3 Correct 6 ms 11212 KB Output is correct
4 Correct 6 ms 11212 KB Output is correct
5 Correct 6 ms 11212 KB Output is correct
6 Correct 6 ms 11212 KB Output is correct
7 Correct 6 ms 11160 KB Output is correct
8 Correct 6 ms 11212 KB Output is correct
9 Correct 6 ms 11212 KB Output is correct
10 Correct 6 ms 11212 KB Output is correct
11 Correct 6 ms 11212 KB Output is correct
12 Correct 6 ms 11212 KB Output is correct
13 Correct 6 ms 11264 KB Output is correct
14 Correct 6 ms 11188 KB Output is correct
15 Correct 7 ms 11184 KB Output is correct
16 Correct 7 ms 11152 KB Output is correct
17 Correct 7 ms 11212 KB Output is correct
18 Correct 8 ms 11212 KB Output is correct
19 Correct 7 ms 11212 KB Output is correct
20 Correct 7 ms 11212 KB Output is correct
21 Correct 8 ms 11344 KB Output is correct
22 Correct 8 ms 11276 KB Output is correct
23 Correct 12 ms 11340 KB Output is correct
24 Correct 12 ms 11412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11212 KB Output is correct
2 Correct 6 ms 11212 KB Output is correct
3 Correct 6 ms 11212 KB Output is correct
4 Correct 6 ms 11212 KB Output is correct
5 Correct 6 ms 11212 KB Output is correct
6 Correct 6 ms 11212 KB Output is correct
7 Correct 6 ms 11160 KB Output is correct
8 Correct 6 ms 11212 KB Output is correct
9 Correct 6 ms 11212 KB Output is correct
10 Correct 6 ms 11212 KB Output is correct
11 Correct 6 ms 11212 KB Output is correct
12 Correct 6 ms 11212 KB Output is correct
13 Correct 6 ms 11264 KB Output is correct
14 Correct 6 ms 11188 KB Output is correct
15 Correct 7 ms 11184 KB Output is correct
16 Correct 7 ms 11152 KB Output is correct
17 Correct 7 ms 11212 KB Output is correct
18 Correct 8 ms 11212 KB Output is correct
19 Correct 7 ms 11212 KB Output is correct
20 Correct 7 ms 11212 KB Output is correct
21 Correct 8 ms 11344 KB Output is correct
22 Correct 8 ms 11276 KB Output is correct
23 Correct 12 ms 11340 KB Output is correct
24 Correct 12 ms 11412 KB Output is correct
25 Correct 10 ms 11340 KB Output is correct
26 Correct 15 ms 11340 KB Output is correct
27 Correct 19 ms 11532 KB Output is correct
28 Correct 70 ms 12648 KB Output is correct
29 Correct 74 ms 12948 KB Output is correct
30 Correct 153 ms 14916 KB Output is correct
31 Correct 116 ms 13688 KB Output is correct
32 Correct 121 ms 14000 KB Output is correct
33 Correct 112 ms 13556 KB Output is correct
34 Correct 115 ms 13564 KB Output is correct
35 Correct 132 ms 14080 KB Output is correct
36 Correct 137 ms 14332 KB Output is correct