This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 200001;
struct node{
ll dp[3];
node(){
for(int j= 0; j < 3; j++){
for(int x = 0; x < 3; x++)
dp[j] = -1e18;
}
}
}t[4 * nmax];
node merg(node a, node b){
node c;
for(int b1 = 0; b1 <= 2; b1++){
for(int b2 = 0; b2 <= 2; b2++){
int x = b1 + b2 - 2 + 1;
c.dp[x] = max(c.dp[x], a.dp[b1] + b.dp[b2]);
}
}
return c;
}
ll a[nmax];
void build(int v, int l, int r){
if(l == r){
t[v].dp[0] = -a[l];
t[v].dp[1] = 0;
t[v].dp[2] = a[l];
return;
}
int m = (l + r) / 2;
build(2 * v, l, m);
build(2 * v + 1, m + 1, r);
t[v] = merg(t[2 * v], t[2 * v + 1]);
}
ll lazy[4 * nmax];
void push(int v){
if(!lazy[v])
return;
t[v * 2].dp[0] -= lazy[v];
t[ v * 2].dp[2] += lazy[v];
t[v * 2 + 1].dp[0] -= lazy[v];
t[v * 2 + 1].dp[2] += lazy[v];
lazy[v * 2] += lazy[v];
lazy[2 * v + 1] += lazy[v];
lazy[v] =0;
}
void update(int v, int l, int r, int st, int fin, ll val){
if(l > fin || r < st){
return;
}
if(l >= st && r <= fin){
t[v].dp[0] += -val;
t[v].dp[2] += val;
lazy[v] += val;
return;
}
int m = (l + r) / 2;
push(v);
update(2 * v, l, m, st, fin, val);
update(2 * v + 1, m + 1, r, st, fin, val);
t[v] = merg(t[2 * v], t[2 * v + 1]);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
int q; cin >> q;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
build(1, 1, n);
// cout << t[1].dp[1] << "\n";
while(q--){
int l, r, c; cin >> l >> r >> c;
update(1,1, n, l, r, c);
cout << t[1].dp[1] << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |