Submission #598046

# Submission time Handle Problem Language Result Execution time Memory
598046 2022-07-17T12:53:32 Z daisy2 Divide and conquer (IZhO14_divide) C++14
0 / 100
2 ms 3412 KB
#include<iostream>
#include<cstring>
#define endl '\n'
using namespace std;
long long n,x[100005],g[100005],e[100005],tree[400005],pr[100005],a[100005],lazy[400005],ans=0; // n<=100000
void build(int node,int l,int r)
{
    if(l==r)
    {
        tree[node]=a[l];
        return;
    }
    int mid=(l+r)/2;

    build(2*node,l,mid);
    build(2*node+1,mid+1,r);

    tree[node]=max(tree[2*node],tree[2*node+1]);
}
int query(int node,int l,int r)
{
    if(tree[node]<0) return -1;

    if(l==r)
    {
        return l;
    }

    if(lazy[node]!=0)
    {
        tree[node]+=lazy[node];
        if(l!=r)
        {
            lazy[2*node]+=lazy[node];
            lazy[2*node+1]+=lazy[node];
        }
        lazy[node]=0;
    }

    int mid=(l+r)/2;

    int a2=query(2*node+1,mid+1,r);
    if(a2>-1) return a2;

    return query(2*node,l,mid);
}
void update(int node,int l,int r,int le,int ri,int st)
{
    if(l>=le && r<=ri)
    {
        lazy[node]+=st;
    }
    if(lazy[node]!=0)
    {
        tree[node]+=lazy[node];
        if(l!=r)
        {
            lazy[2*node]+=lazy[node];
            lazy[2*node+1]+=lazy[node];
        }
        lazy[node]=0;
    }
    if(l>ri || r<le) return;
    if(l>=le && r<=ri) return;

    int mid=(l+r)/2;
    update(2*node,l,mid,le,ri,st);
    update(2*node+1,mid+1,r,le,ri,st);

    tree[node]=max(tree[2*node],tree[2*node+1]);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;

    for(int i=1;i<=n;i++)
    {
        cin>>x[i]>>g[i]>>e[i];

        g[i]+=g[i-1];

        pr[i]=pr[i-1]+e[i];
        a[i]=pr[i]-x[i]+x[1];
    }
    memset(tree,-1,sizeof(tree));

    build(1,1,n);

    for(int i=1;i<=n;i++)
    {
        ans=max(ans,g[query(1,1,n)]-g[i-1]);
        update(1,1,n,i+1,n,x[i+1]-x[i]-e[i]);
    }
 cout<<ans<<endl;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 3412 KB Output is correct
2 Incorrect 2 ms 3412 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3412 KB Output is correct
2 Incorrect 2 ms 3412 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3412 KB Output is correct
2 Incorrect 2 ms 3412 KB Output isn't correct
3 Halted 0 ms 0 KB -