이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define lf (h << 1)
#define rf ((h << 1) | 1)
using namespace std;
const int N = 2e5 + 5;
ll n, q, a[N], d[N], v[4 * N][3][3];
void upd(int h, int l, int r, int id) {
	if (id < l || r < id) return ;
	if (l == id && id == r) {
		v[h][1][1] = abs(d[id]);
		return ;
	}
	int m = (l + r) >> 1;
	upd(lf, l, m, id);
	upd(rf, m + 1, r, id);
	
	v[h][1][1] = max(v[lf][1][0] + v[rf][1][1], v[lf][1][1] + v[rf][0][1]);
	v[h][1][0] = max(v[lf][1][0] + v[rf][1][0], v[lf][1][1] + v[rf][0][0]);
	v[h][0][1] = max(v[lf][0][0] + v[rf][1][1], v[lf][0][1] + v[rf][0][1]);
	v[h][0][0] = max(v[lf][0][0] + v[rf][1][0], v[lf][0][1] + v[rf][0][0]);
	
	if ((d[m] >= 0 && d[m + 1] >= 0) || (d[m] <= 0 && d[m + 1] <= 0)) {
		v[h][1][1] = max(v[lf][1][0], v[lf][1][1]) + max(v[rf][0][1], v[rf][1][1]);
		v[h][1][0] = max(v[lf][1][0], v[lf][1][1]) + max(v[rf][0][0], v[rf][1][0]);
		v[h][0][1] = max(v[lf][0][0], v[lf][0][1]) + max(v[rf][0][1], v[rf][1][1]);
		v[h][0][0] = max(v[lf][0][0], v[lf][0][1]) + max(v[rf][0][0], v[rf][1][0]);
	}
}
main () {
	cin >> n >> q;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	
	for (int i = 1; i < n; ++i) {
		d[i] = a[i + 1] - a[i];
		upd(1, 1, n - 1, i);
	}
	
	for (int i = 1; i <= q; ++i) {
		int l, r, x;
		cin >> l >> r >> x;
		d[r] -= x;
		upd(1, 1, n - 1, r);
		
		if (l - 1) {
			d[l - 1] += x;
			upd(1, 1, n - 1, l - 1);
		}
	
		cout << max(max(v[1][0][0], v[1][1][1]), max(v[1][0][1], v[1][1][0])) << "\n";
	}
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp:36:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   36 | main () {
      |       ^| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |