#include <bits/stdc++.h>
#define task "testing"
#define int long long
#define multitest 0
using namespace std;
struct Data {
int val, a[2][2];
Data() {
val = a[0][0] = a[0][1] = a[1][0] = a[1][1] = 0;
}
};
const int N = 2e5;
int a[N+5];
Data st[4*N+5];
Data merge(Data u, Data v) {
Data res;
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 2; y++) {
for (int z = 0; z < 2; z++) {
res.a[x][y] = max(res.a[x][y], u.a[x][z]+v.a[z][y]);
}
}
}
return res;
}
void upd(int nd, int lf, int rt, int u, int v) {
if (u < lf || rt < u) return;
if (lf == rt) {
st[nd].val += v;
if (st[nd].val < 0) {
st[nd].a[0][0] = -st[nd].val, st[nd].a[0][1] = st[nd].a[1][0] = st[nd].a[1][1] = 0;
}
else {
st[nd].a[0][0] = st[nd].a[0][1] = st[nd].a[1][0] = 0, st[nd].a[1][1] = st[nd].val;
}
return;
}
int mid = (lf+rt)/2;
upd(nd*2, lf, mid, u, v);
upd(nd*2+1, mid+1, rt, u, v);
st[nd] = merge(st[nd*2], st[nd*2+1]);
}
void flo(int ID) {
int n, q; cin >> n >> q;
for (int x = 1; x <= n; x++) cin >> a[x];
for (int x = 1; x < n; x++) {
upd(1, 1, n-1, x, a[x+1]-a[x]);
}
while (q--) {
int l, r, x; cin >> l >> r >> x;
upd(1, 1, n-1, l-1, x);
upd(1, 1, n-1, r, -x);
int ans = 0;
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 2; y++) {
ans = max(ans, st[1].a[x][y]);
}
}
cout << ans << "\n";
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int TCS = 1, ID = 1;
if (multitest) {
cin >> TCS;
}
while (TCS--) flo(ID++);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:91:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:92:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
92 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |