Submission #1168485

#TimeUsernameProblemLanguageResultExecution timeMemory
1168485PlayVoltzSjeckanje (COCI21_sjeckanje)C++20
0 / 110
1 ms320 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 t){ if (s==e)val[t][t]=nv, val[!t][!t]=val[t][!t]=val[!t][t]=0; else{ if (ind<=m)l->up(ind, nv, t); else r->up(ind, nv, t); 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 node2{ int s, e, m, val, lazy; node2 *l, *r; void create(){ if (l==nullptr){ l = new node2(s, m); r = new node2(m+1, e); } } void propagate(){ val+=lazy*(e-s+1); if (s!=e){ create(); l->lazy+=lazy; r->lazy+=lazy; } lazy=0; } node2(int S, int E){ s = S, e = E, m = (s+e)/2; val=lazy=0; l=r=nullptr; } void up(int left, int right, int v){ propagate(); if (s==left && e==right)lazy+=v; else{ create(); if (right<=m)l->up(left, right, v); else if (left>m)r->up(left, right, v); else l->up(left, m, v), r->up(m+1, right, v); r->propagate(), l->propagate(); val=l->val+r->val; } } int query(int left, int right){ propagate(); if (s==left && e==right)return val; create(); if (right<=m)return l->query(left, right); else if (left>m)return r->query(left, right); else return l->query(left, m)+r->query(m+1, right); } }*st2; int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q, a, b, c; cin>>n>>q; if (n==1){ while (q--)cout<<"0\n"; } st = new node(2, n); st2 = new node2(1, 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 t=0; if (1<i&&i<n)t=((vect[i-1]<vect[i]&&vect[i+1]<vect[i])||(vect[i-1]>vect[i]&&vect[i+1]>vect[i])); if (!t&&1<=i-2&&i<=n)t=((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]), t); } while (q--){ cin>>a>>b>>c; st2->up(a, b, c); 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 (!ta&&1<=a-2&&a<=n)ta=((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 (1<b&&b<n)tb=((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 (a>1)st->up(a, abs(st2->query(a, a)-st2->query(a-1, a-1)), ta); if (b<n)st->up(b+1, abs(st2->query(b, b)-st2->query(b+1, b+1)), 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...