이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 1000000007
#define LOGN 20
#define MAXN 200005
struct node {
ll left, right;
ll l0r0, l0r1, l1r0, l1r1;
};
node merge(node a, node b) {
node temp;
temp.left = a.left;
temp.right = b.right;
if (a.right != b.left) {
temp.l1r1 = max(abs(a.l1r0) + abs(b.l1r1), abs(a.l1r1) + abs(b.l0r1));
temp.l1r0 = max(abs(a.l1r0) + abs(b.l1r0), abs(a.l1r1) + abs(b.l0r0));
temp.l0r1 = max(abs(a.l0r0) + abs(b.l1r1), abs(a.l0r1) + abs(b.l0r1));
temp.l0r0 = max(abs(a.l0r0) + abs(b.l1r0), abs(a.l0r1) + abs(b.l0r0));
} else {
temp.l1r1 = abs(a.l1r1) + abs(b.l1r1);
temp.l1r0 = abs(a.l1r1) + abs(b.l1r0);
temp.l0r1 = abs(a.l0r1) + abs(b.l1r1);
temp.l0r0 = abs(a.l0r1) + abs(b.l1r0);
}
return temp;
}
vector<ll> arr, diff;
node sg[4*MAXN];
void init(int k, int a, int b) {
if (a == b) {
sg[k].left = sg[k].right = sg[k].l1r1 = diff[a];
sg[k].l0r0 = sg[k].l0r1 = sg[k].l1r0 = 0;
return ;
}
init(2*k, a, (a+b)/2);
init(2*k+1, (a+b)/2+1, b);
sg[k] = merge(sg[2*k], sg[2*k+1]);
}
void point_update(int k, int a, int b, int plc, ll val) {
if (a > plc || b < plc)
return ;
if (a == b) {
sg[k].left = sg[k].right += val;
sg[k].l1r1 = abs(sg[k].right);
sg[k].l0r0 = sg[k].l0r1 = sg[k].l1r0 = 0;
return ;
}
point_update(2*k, a, (a+b)/2, plc, val);
point_update(2*k+1, (a+b)/2+1, b, plc, val);
sg[k] = merge(sg[2*k], sg[2*k+1]);
}
int main() {
fast
ll n, q;
cin >> n >> q;
arr = vector<ll>(n+1);
diff = vector<ll>(n+1);
for (int i = 1; i <= n; i++)
cin >> arr[i];
for (int i = 2; i <= n; i++)
diff[i-1] = arr[i] - arr[i-1];
init(1, 1, n-1);
while (q--) {
ll l, r, val;
cin >> l >> r >> val;
if (l != 1)
point_update(1, 1, n-1, l-1, val);
if (r != n)
point_update(1, 1, n-1, r, -val);
cout << sg[1].l1r1 << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |