Submission #1001144

# Submission time Handle Problem Language Result Execution time Memory
1001144 2024-06-18T15:38:53 Z vjudge3 Foehn Phenomena (JOI17_foehn_phenomena) C++17
100 / 100
494 ms 24148 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll a[200005], s, t;
int n;

struct Node {
	ll x, lz;
} seg[800005];

void build (int id, int l, int r) {
	if (l == r) {
		seg[id].x = a[l];
		return;
	}
	build(id*2, l, (l+r)/2);
	build(id*2+1, (l+r)/2+1, r);
}

void push (int id) {
	seg[id].x += seg[id].lz;
	if (id <= n*2) {
		seg[id*2].lz += seg[id].lz;
		seg[id*2+1].lz += seg[id].lz;
	}
	seg[id].lz = 0;
}

void upd (int id, int l, int r, int ql, int qr, ll val) {
	push(id);
	if (qr < l || r < ql) return;
	if (ql <= l && r <= qr) {
		seg[id].lz += val;
		push(id);
		return;
	}
	upd(id*2, l, (l+r)/2, ql, qr, val);
	upd(id*2+1, (l+r)/2+1, r, ql, qr, val);
}

ll query (int id, int l, int r, int idx) {
	push(id);
	if (l == r) return seg[id].x;
	int mid = (l+r)/2;
	if (mid < idx) return query(id*2+1, mid+1, r, idx);
	return query(id*2, l, mid, idx);
}

ll upd (int idx) {
	ll cur = query(1, 1, n, idx);
	ll prv = idx == 1 ? 0 : query(1, 1, n, idx-1);
	ll nxt = idx == n ? cur : query(1, 1, n, idx+1);
	ll res = 0;
	if (prv < cur) res -= (cur - prv) * s;
	else res += (prv - cur) * t;
	if (cur < nxt) res -= (nxt - cur) * s;
	else res += (cur - nxt) * t;
	return res;
}

int main () {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int q;
	cin >> n >> q >> s >> t >> a[0];
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i-1] < a[i]) ans -= (a[i] - a[i-1]) * s;
		else ans += (a[i-1] - a[i]) * t;
	}
	build(1, 1, n);
	while (q--) {
		int l, r;
		ll x;
		cin >> l >> r >> x;
		ans -= upd(l) + (l == r ? 0 : upd(r));
		upd(1, 1, n, l, r, x);
		ans += upd(l) + (l == r ? 0 : upd(r));
		cout << ans << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 4 ms 612 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 3 ms 624 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 4 ms 604 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 568 KB Output is correct
15 Correct 3 ms 600 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 408 ms 15872 KB Output is correct
2 Correct 411 ms 16396 KB Output is correct
3 Correct 415 ms 16976 KB Output is correct
4 Correct 403 ms 16200 KB Output is correct
5 Correct 410 ms 17036 KB Output is correct
6 Correct 215 ms 13140 KB Output is correct
7 Correct 215 ms 13060 KB Output is correct
8 Correct 369 ms 17448 KB Output is correct
9 Correct 372 ms 17744 KB Output is correct
10 Correct 377 ms 16464 KB Output is correct
11 Correct 233 ms 13136 KB Output is correct
12 Correct 211 ms 13400 KB Output is correct
13 Correct 318 ms 18512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 4 ms 612 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 3 ms 624 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 4 ms 604 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 568 KB Output is correct
15 Correct 3 ms 600 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 408 ms 15872 KB Output is correct
23 Correct 411 ms 16396 KB Output is correct
24 Correct 415 ms 16976 KB Output is correct
25 Correct 403 ms 16200 KB Output is correct
26 Correct 410 ms 17036 KB Output is correct
27 Correct 215 ms 13140 KB Output is correct
28 Correct 215 ms 13060 KB Output is correct
29 Correct 369 ms 17448 KB Output is correct
30 Correct 372 ms 17744 KB Output is correct
31 Correct 377 ms 16464 KB Output is correct
32 Correct 233 ms 13136 KB Output is correct
33 Correct 211 ms 13400 KB Output is correct
34 Correct 318 ms 18512 KB Output is correct
35 Correct 450 ms 21376 KB Output is correct
36 Correct 424 ms 22868 KB Output is correct
37 Correct 404 ms 23728 KB Output is correct
38 Correct 414 ms 23476 KB Output is correct
39 Correct 431 ms 23368 KB Output is correct
40 Correct 416 ms 23376 KB Output is correct
41 Correct 423 ms 23316 KB Output is correct
42 Correct 442 ms 23276 KB Output is correct
43 Correct 436 ms 22868 KB Output is correct
44 Correct 450 ms 22956 KB Output is correct
45 Correct 494 ms 23116 KB Output is correct
46 Correct 463 ms 24148 KB Output is correct
47 Correct 252 ms 18260 KB Output is correct
48 Correct 151 ms 18488 KB Output is correct
49 Correct 445 ms 21600 KB Output is correct
50 Correct 250 ms 18120 KB Output is correct
51 Correct 223 ms 18592 KB Output is correct
52 Correct 401 ms 18516 KB Output is correct