Submission #140528

# Submission time Handle Problem Language Result Execution time Memory
140528 2019-08-03T11:32:01 Z rzbt Divide and conquer (IZhO14_divide) C++14
100 / 100
129 ms 10528 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 100005
typedef long long ll;

using namespace std;

pair<ll,pair<ll,ll> >  niz[MAXN];

ll n;
ll prefix[MAXN];
ll seg[4*MAXN];
ll lazy[4*MAXN];




void izgradi(ll l,ll d,ll k){
    seg[k]=-1e9-7;
    if(l==d)
        return;

    ll mid=(l+d)/2;
    izgradi(l,mid,k+k);
    izgradi(mid+1,d,k+k+1);
}

void dodaj(ll l,ll d,ll tl,ll td,ll x,ll k){
    if(lazy[k]){
        seg[k]+=lazy[k];
        if(l!=d){
            lazy[k+k]+=lazy[k];
            lazy[k+k+1]+=lazy[k];
        }
        lazy[k]=0;
    }
    if(l>td || d<tl)return;
    if(l>=tl && d<=td){
        lazy[k]=x;
        seg[k]+=lazy[k];
        if(l!=d){
            lazy[k+k]+=lazy[k];
            lazy[k+k+1]+=lazy[k];
        }
        lazy[k]=0;
        return;
    }
    ll mid=(l+d)/2;
    dodaj(l,mid,tl,td,x,k+k);
    dodaj(mid+1,d,tl,td,x,k+k+1);

    seg[k]=max(seg[k+k],seg[k+k+1]);
}

void odsljakaj(ll l,ll d,ll k){
    if(lazy[k]){
        seg[k]+=lazy[k];
        if(l!=d){
            lazy[k+k]+=lazy[k];
            lazy[k+k+1]+=lazy[k];
        }
        lazy[k]=0;
    }
}


ll setnja(ll l,ll d,ll k){
    if(seg[k]<0)return -1;
    if(l==d)return l;

    ll mid=(l+d)/2;
    odsljakaj(l,mid,k+k);
    odsljakaj(mid+1,d,k+k+1);

    if(seg[k+k]>=0)return setnja(l,mid,k+k);
    else return setnja(mid+1,d,k+k+1);


}

ll res;


int main()
{
    scanf("%lld", &n);
    for(ll i=1;i<=n;i++){
        ll x,g,e;
        scanf("%lld %lld %lld", &x, &g, &e);
        niz[i]=mp(x,mp(g,e));
    }
    izgradi(1,n,1);
    prefix[1]=niz[1].second.first;
    res=prefix[1];
    dodaj(1,n,1,1,niz[1].S.S,1);
    dodaj(1,n,1,1,1e9+7,1);
    for(ll i=2;i<=n;i++){
        prefix[i]=prefix[i-1]+niz[i].S.F;
        dodaj(1,n,i,i,1e9+7,1);
        dodaj(1,n,1,i,niz[i].S.S,1);
        dodaj(1,n,1,i-1,niz[i-1].F-niz[i].F,1);
        ll gde=setnja(1,n,1);
        if(gde==-1){
            printf("SDAFGFAFAFSSAF");
            return 0;
        }
        res=max(res,prefix[i]-prefix[gde-1]);

    }
    printf("%lld",res);
    return 0;
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:90:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &n);
     ~~~~~^~~~~~~~~~~~
divide.cpp:93:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld %lld", &x, &g, &e);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 404 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 7 ms 888 KB Output is correct
12 Correct 8 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 888 KB Output is correct
2 Correct 12 ms 1272 KB Output is correct
3 Correct 12 ms 1400 KB Output is correct
4 Correct 58 ms 4984 KB Output is correct
5 Correct 61 ms 5340 KB Output is correct
6 Correct 129 ms 10528 KB Output is correct
7 Correct 114 ms 9268 KB Output is correct
8 Correct 115 ms 9340 KB Output is correct
9 Correct 113 ms 9208 KB Output is correct
10 Correct 111 ms 9208 KB Output is correct
11 Correct 118 ms 9820 KB Output is correct
12 Correct 121 ms 9848 KB Output is correct