제출 #1231865

#제출 시각아이디문제언어결과실행 시간메모리
1231865antromancapFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
96 ms6468 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;
int n, Q, a[N], S, T;
long long bit[N];

void upd(int i, int x) {
	for (; i <= n; i += i & -i) bit[i] += x;
}
long long get(int i) {
	long long res = 0;
	for (; i; i -= i & -i) res += bit[i];
	return res;
}
long long calc(long long x, long long y) { return (x < y ? S : T) * abs(x - y); }

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> Q >> S >> T;
	S = -S;
	n++;
	long long res = 0;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i < n; i++) res += calc(a[i], a[i + 1]);
	for (int i = 1; i <= n; i++) upd(i, a[i] - a[i - 1]);
	while (Q--) {
		int l, r, x;
		cin >> l >> r >> x;
		l++, r++;
		if (l > 1) res += calc(get(l - 1), get(l) + x) - calc(get(l - 1), get(l));
		if (r < n) res += calc(get(r) + x, get(r + 1)) - calc(get(r), get(r + 1));
		upd(l, x);
		upd(r + 1, -x);
		cout << res << '\n';
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...