#include using namespace std; #include #include template struct lazysegtree{ using F=function; using G=function; const F calcfn,lazycalcfn; const G updatefn; int n; T defvalue,lazydefvalue; vectordat,lazy; vectorlazyflag; lazysegtree(int n_=0,T defvalue_=0, const F calcfn_=[](T a,T b){return a+b;}, const F lazycalcfn_=[](T a,T b){return a+b;}, const G updatefn_=[](T a,T b,int l,int r){return a+b*(r-l);}, T lazydefvalue_=0 ):defvalue(defvalue_),lazydefvalue(lazydefvalue_), calcfn(calcfn_),lazycalcfn(lazycalcfn_),updatefn(updatefn_) { n=1; while(n&v) { for(int i=0;i=0;i--)dat[i]=calcfn(dat[2*i+1],dat[2*i+2]); } void eval(int i,int l,int r) { if(lazyflag[i]) { dat[i]=updatefn(dat[i],lazy[i],l,r); if(r-l>1) { lazy[2*i+1]=lazycalcfn(lazy[2*i+1],lazy[i]); lazy[2*i+2]=lazycalcfn(lazy[2*i+2],lazy[i]); lazyflag[2*i+1]=lazyflag[2*i+2]=true; } lazy[i]=lazydefvalue; lazyflag[i]=false; } } void update(int a,int b,T x,int k=0,int l=0,int r=-1)//[a,b) { if(r<0)r=n; eval(k,l,r); if(b<=l||r<=a)return; else if(a<=l&&r<=b) { lazy[k]=lazycalcfn(lazy[k],x); lazyflag[k]=true; eval(k,l,r); } else { update(a,b,x,2*k+1,l,(l+r)/2); update(a,b,x,2*k+2,(l+r)/2,r); dat[k]=calcfn(dat[2*k+1],dat[2*k+2]); } } T query(int a,int b,int k=0,int l=0,int r=-1)//[a,b) { if(r<0)r=n; eval(k,l,r); if(b<=l||r<=a)return defvalue; else if(a<=l&&r<=b)return dat[k]; else return calcfn( query(a,b,2*k+1,l,(l+r)/2), query(a,b,2*k+2,(l+r)/2,r) ); } }; int N; main() { cin>>N; lazysegtree >P(N-1,make_pair(0,0), [](paira,pairb){ return make_pair(max(a.first,b.first-a.second),a.second+b.second); }, [](paira,pairb){return make_pair(a.first+b.first,0L);}, [](paira,pairb,int l,int r){return make_pair(a.first+b.first,a.second);}, make_pair(0,0)); vector >init(N-1); for(int i=0;i>init[i].first; init[i].second=3; } P.copy(init); int M;cin>>M; for(;M--;) { long l,r,d;cin>>l>>r>>d; P.update(l-1,r,make_pair(d,0L)); pairp=P.query(0,N-1); cout<