Submission #674495

#TimeUsernameProblemLanguageResultExecution timeMemory
674495alexddSjeckanje (COCI21_sjeckanje)C++17
0 / 110
1 ms332 KiB
#pragma GCC optimize("O3,unroll-loops") #include<bits/stdc++.h> using namespace std; struct node { int score; int maxst,minst,capst; int maxdr,mindr,capdr; }; node combine(node x, node y) { node rez; if(x.score + y.score < x.score - (x.maxdr - x.mindr) + y.score - (y.maxst - y.minst) + max(y.maxst, x.maxdr) - min(y.minst, x.minst)) { rez.score = x.score - (x.maxdr - x.mindr) + y.score - (y.maxst - y.minst) + max(y.maxst, x.maxdr) - min(y.minst, x.minst); if(x.capdr <= x.capst)///secventa stanga = secventa dreapta { rez.maxst = max(x.maxst, y.maxst); rez.minst = min(x.minst, y.minst); rez.capst = y.capst; } else { rez.maxst = x.maxst; rez.minst = x.minst; rez.capst = x.capst; } if(y.capdr <= y.capst) { rez.maxdr = max(y.maxdr, x.maxdr); rez.mindr = min(y.mindr, x.mindr); rez.capdr = x.capdr; } else { rez.maxdr = y.maxdr; rez.mindr = y.mindr; rez.capdr = y.capdr; } } else { rez.score = x.score + y.score; rez.maxdr = y.maxdr; rez.mindr = y.mindr; rez.capdr = y.capdr; rez.maxst = x.maxst; rez.minst = x.minst; rez.capst = x.capst; } return rez; } int n,q; int a[200001]; node aint[810001]; int lazy[810001]; void build(int nod, int st, int dr) { if(st==dr) { aint[nod]={0,a[st],a[st],st,a[st],a[st],st}; return; } int mij=(st+dr)/2; build(nod*2,st,mij); build(nod*2+1,mij+1,dr); aint[nod]=combine(aint[nod*2],aint[nod*2+1]); } void propagate(int nod) { aint[nod].maxdr+=lazy[nod]; aint[nod].maxst+=lazy[nod]; aint[nod].minst+=lazy[nod]; aint[nod].mindr+=lazy[nod]; lazy[nod*2]+=lazy[nod]; lazy[nod*2+1]+=lazy[nod]; lazy[nod]=0; } void upd(int nod, int st, int dr, int le, int ri, int newval) { if(le>ri) return; if(st==le && dr==ri) { lazy[nod]+=newval; return; } int mij=(st+dr)/2; upd(nod*2,st,mij,le,min(mij,ri),newval); upd(nod*2+1,mij+1,dr,max(mij+1,le),ri,newval); propagate(nod*2); propagate(nod*2+1); aint[nod]=combine(aint[nod*2],aint[nod*2+1]); } signed main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>q; for(int i=1;i<=n;i++) { cin>>a[i]; } build(1,1,n); int l,r,x; for(int i=0;i<q;i++) { cin>>l>>r>>x; upd(1,1,n,l,r,x); propagate(1); cout<<aint[1].score<<"\n"; } return 0; } /** */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...