Submission #1168521

#TimeUsernameProblemLanguageResultExecution timeMemory
1168521PlayVoltzSjeckanje (COCI21_sjeckanje)C++20
110 / 110
989 ms39428 KiB
#include <cstdio> #include <stdio.h> #include <stdbool.h> #include <iostream> #include <map> #include <vector> #include <climits> #include <stack> #include <string> #include <queue> #include <algorithm> #include <set> #include <unordered_set> #include <unordered_map> #include <cmath> #include <cctype> #include <bitset> #include <iomanip> #include <cstring> #include <numeric> #include <cassert> using namespace std; #define int long long #define pii pair<int, int> #define mp make_pair #define pb push_back #define fi first #define se second struct node{ int s, e, m, val[2][2]; node *l, *r; node(int S, int E){ s = S, e = E, m = (s+e)/2; val[0][0]=val[0][1]=val[1][0]=val[1][1]=0; if (s!=e){ l = new node(s, m); r = new node(m+1, e); } } void up(int ind, int nv, bool ta, bool tb){ if (s==e)val[0][0]=val[0][1]=val[1][0]=val[1][1]=0, val[ta][tb]=nv; else{ if (ind<=m)l->up(ind, nv, ta, tb); else r->up(ind, nv, ta, tb); int a[2][2], b[2][2]; a[0][0]=l->val[0][0]; a[0][1]=l->val[0][1]; a[1][0]=l->val[1][0]; a[1][1]=l->val[1][1]; b[0][0]=r->val[0][0]; b[0][1]=r->val[0][1]; b[1][0]=r->val[1][0]; b[1][1]=r->val[1][1]; val[0][0]=val[0][1]=val[1][0]=val[1][1]=0; val[0][0]=max({a[0][0]+max(b[0][0], b[1][0]), max(a[0][1], a[0][0])+b[0][0]}); val[1][1]=max({a[1][0]+max(b[0][1], b[1][1]), max(a[1][1], a[1][0])+b[0][1]}); val[0][1]=max({a[0][0]+max(b[0][1], b[1][1]), max(a[0][1], a[0][0])+b[0][1]}); val[1][0]=max({a[1][0]+max(b[0][0], b[1][0]), max(a[1][1], a[1][0])+b[0][0]}); } } }*st; struct fen{ int n; vector<int> ft1, ft2; fen(int N){ n=N; ft1.resize(n+1, 0); ft2.resize(n+1, 0); } void up(int l, int r, int v){ for (int i=l; i<=n; i+=i&-i)ft1[i]+=v, ft2[i]-=v*(l-1); for (int i=r+1; i<=n; i+=i&-i)ft1[i]-=v, ft2[i]+=v*r; } int sum(int i){ int res=0; for (int p=i;p;p-=p&-p)res+=ft1[p]*i+ft2[p]; return res; } int query(int l, int r){ return sum(r)-sum(l-1); } }*st2; int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q, aa, bb, cc; cin>>n>>q; if (n==1){ while (q--)cout<<"0\n"; } st = new node(2, n); st2 = new fen(n); vector<int> vect(n+1); for (int i=1; i<=n; ++i)cin>>vect[i], st2->up(i, i, vect[i]); for (int i=2; i<=n; ++i){ bool ta=0, tb=0; if (1<i&&i<n)tb=((vect[i-1]<vect[i]&&vect[i+1]<vect[i])||(vect[i-1]>vect[i]&&vect[i+1]>vect[i])); if (1<=i-2&&i<=n)ta=((vect[i-2]<vect[i-1]&&vect[i]<vect[i-1])||(vect[i-2]>vect[i-1]&&vect[i]>vect[i-1])); st->up(i, abs(vect[i]-vect[i-1]), ta, tb); } while (q--){ cin>>aa>>bb>>cc; st2->up(aa, bb, cc); for (int a=aa-1; a<=aa+1; ++a){ bool ta=0, tb=0; if (1<a&&a<n)ta=((st2->query(a-1, a-1)<st2->query(a, a)&&st2->query(a+1, a+1)<st2->query(a, a))||(st2->query(a-1, a-1)>st2->query(a, a)&&st2->query(a+1, a+1)>st2->query(a, a))); if (1<=a-2&&a<=n)tb=((st2->query(a-2, a-2)<st2->query(a-1, a-1)&&st2->query(a, a)<st2->query(a-1, a-1))||(st2->query(a-2, a-2)>st2->query(a-1, a-1)&&st2->query(a, a)>st2->query(a-1, a-1))); if (a>1&&a<=n)st->up(a, abs(st2->query(a, a)-st2->query(a-1, a-1)), tb, ta); } for (int b=bb-1; b<=bb+1; ++b){ bool ta=0, tb=0; if (1<b&&b<n)ta=((st2->query(b-1, b-1)<st2->query(b, b)&&st2->query(b+1, b+1)<st2->query(b, b))||(st2->query(b-1, b-1)>st2->query(b, b)&&st2->query(b+1, b+1)>st2->query(b, b))); if (!tb&&1<=b&&b+2<=n)tb=((st2->query(b, b)<st2->query(b+1, b+1)&&st2->query(b+2, b+2)<st2->query(b+1, b+1))||(st2->query(b, b)>st2->query(b+1, b+1)&&st2->query(b+2, b+2)>st2->query(b+1, b+1))); if (1<=b&&b<n)st->up(b+1, abs(st2->query(b, b)-st2->query(b+1, b+1)), ta, tb); } cout<<max({st->val[0][0], st->val[0][1], st->val[1][0], st->val[1][1]})<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...