Submission #735500

#TimeUsernameProblemLanguageResultExecution timeMemory
735500bgnbvnbvSjeckanje (COCI21_sjeckanje)C++14
110 / 110
700 ms69548 KiB
#include<bits/stdc++.h> #define TASKNAME "codeforce" #define pb push_back #define pli pair<int,int> #define fi first #define se second #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); using namespace std; using ll=long long; const ll maxN=3e5; const ll inf=1e18; const ll mod=1e9+7; ll n; struct node { ll dau,cuoi; ll a[2][2]; node() { dau=0,cuoi=0; for(int i=0;i<2;i++) for(int j=0;j<2;j++) a[i][j]=0; } node operator+(const node&o) { node ans; ans.dau=dau; ans.cuoi=o.cuoi; for(int i=0;i<2;i++) { for(int j=0;j<2;j++) { for(int k=0;k<2;k++) { ans.a[i][j]=max(ans.a[i][j],a[i][k]+o.a[1-k][j]); } if(cuoi*o.dau>0) ans.a[i][j]=max(ans.a[i][j],a[i][1]+o.a[1][j]); } } return ans; } }st[4*maxN]; void update(ll pos,ll val,ll id=1,ll l=2,ll r=n) { if(pos==1) return; if(l==r) { st[id].dau=st[id].cuoi=val; st[id].a[1][1]=abs(val); return; } ll mid=l+r>>1; if(pos<=mid) update(pos,val,id*2,l,mid); else update(pos,val,id*2+1,mid+1,r); st[id]=st[id*2]+st[id*2+1]; } ll q,a[maxN],b[maxN]; void solve() { cin >> n >> q; for(int i=1;i<=n;i++) cin >> a[i],update(i,a[i]-a[i-1]),b[i]=a[i]-a[i-1]; for(int i=1;i<=q;i++) { ll l,r,x; cin >> l >> r >> x; b[l]+=x; update(l,b[l]); r++; if(r<=n) { b[r]-=x; update(r,b[r]); } cout<< max({st[1].a[0][0],st[1].a[1][0],st[1].a[1][1],st[1].a[0][1]})<<'\n'; } } int main() { fastio //freopen(TASKNAME".INP","r",stdin); //freopen(TASKNAME".OUT","w",stdout); solve(); }

Compilation message (stderr)

Main.cpp: In function 'void update(ll, ll, ll, ll, ll)':
Main.cpp:51:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |     ll mid=l+r>>1;
      |            ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...