Submission #598057

# Submission time Handle Problem Language Result Execution time Memory
598057 2022-07-17T13:13:10 Z daisy2 Divide and conquer (IZhO14_divide) C++14
100 / 100
59 ms 9384 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(long long node,long long l,long long r)
{
    if(l==r)
    {
        tree[node]=a[l];
        return;
    }
    long long 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]);
}
long long query(long long node,long long l,long long r)
{
    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(tree[node]<0) return -1;
    if(l==r)
        return l;

    long long mid=(l+r)/2;

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

    return query(2*node,l,mid);
}
void update(long long node,long long l,long long r,long long le,long long ri,long long 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;

    long long 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(long long 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);

    long long p;
    for(long long i=1;i<=n;i++)
    {
        p=query(1,1,n);
        if(p==-1) continue;

        ans=max(ans,g[p]-g[i-1]);

        if(i!=n)
        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 Correct 1 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 1 ms 3412 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
7 Correct 2 ms 3412 KB Output is correct
8 Correct 2 ms 3412 KB Output is correct
9 Correct 2 ms 3412 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
11 Correct 2 ms 3412 KB Output is correct
12 Correct 1 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3412 KB Output is correct
2 Correct 1 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 1 ms 3412 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
7 Correct 2 ms 3412 KB Output is correct
8 Correct 2 ms 3412 KB Output is correct
9 Correct 2 ms 3412 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
11 Correct 2 ms 3412 KB Output is correct
12 Correct 1 ms 3412 KB Output is correct
13 Correct 1 ms 3412 KB Output is correct
14 Correct 2 ms 3412 KB Output is correct
15 Correct 2 ms 3412 KB Output is correct
16 Correct 2 ms 3412 KB Output is correct
17 Correct 2 ms 3436 KB Output is correct
18 Correct 2 ms 3516 KB Output is correct
19 Correct 2 ms 3540 KB Output is correct
20 Correct 2 ms 3540 KB Output is correct
21 Correct 2 ms 3540 KB Output is correct
22 Correct 4 ms 3540 KB Output is correct
23 Correct 4 ms 3796 KB Output is correct
24 Correct 4 ms 3796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3412 KB Output is correct
2 Correct 1 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 1 ms 3412 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
7 Correct 2 ms 3412 KB Output is correct
8 Correct 2 ms 3412 KB Output is correct
9 Correct 2 ms 3412 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
11 Correct 2 ms 3412 KB Output is correct
12 Correct 1 ms 3412 KB Output is correct
13 Correct 1 ms 3412 KB Output is correct
14 Correct 2 ms 3412 KB Output is correct
15 Correct 2 ms 3412 KB Output is correct
16 Correct 2 ms 3412 KB Output is correct
17 Correct 2 ms 3436 KB Output is correct
18 Correct 2 ms 3516 KB Output is correct
19 Correct 2 ms 3540 KB Output is correct
20 Correct 2 ms 3540 KB Output is correct
21 Correct 2 ms 3540 KB Output is correct
22 Correct 4 ms 3540 KB Output is correct
23 Correct 4 ms 3796 KB Output is correct
24 Correct 4 ms 3796 KB Output is correct
25 Correct 4 ms 3796 KB Output is correct
26 Correct 6 ms 4052 KB Output is correct
27 Correct 6 ms 4052 KB Output is correct
28 Correct 30 ms 6352 KB Output is correct
29 Correct 29 ms 6444 KB Output is correct
30 Correct 59 ms 9292 KB Output is correct
31 Correct 53 ms 9384 KB Output is correct
32 Correct 58 ms 9372 KB Output is correct
33 Correct 51 ms 9348 KB Output is correct
34 Correct 52 ms 9292 KB Output is correct
35 Correct 52 ms 9348 KB Output is correct
36 Correct 54 ms 9292 KB Output is correct