Submission #1180091

#TimeUsernameProblemLanguageResultExecution timeMemory
1180091jbarejaFoehn Phenomena (JOI17_foehn_phenomena)C++20
0 / 100
49 ms3652 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int N; // N+1 - liczba miejsc o danych wysokościach
int Q; // liczba zapytań
ll S; // zmniejszenie temperatury na jednostkę wysokości, jeżeli wysokość się zwiększa
ll T; // zwiększenie temperatury na jednostkę wysokości, jeżeli wysokość się zmniejsza

vector<ll> A;

ll ans() {
	ll temperature = 0;
	for (int i=1; i<=N; i++) {
		if (A[i] > A[i-1]) temperature -= abs(A[i] - A[i-1]) * S;
		else temperature += abs(A[i] - A[i-1]) * T;
	}
	return temperature;
}

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

	cin >> N >> Q >> S >> T;

	A.assign(N+1, 0);

	for (int i=0; i<=N; i++) cin >> A[i];

	if (S == T) {
		ll h = A[N];
		for (int i=0; i<Q; i++) {
			int L, R; ll X;
			cin >> L >> R >> X;
			if (R == N) h += X;
			cout << h * S << '\n';
		}
		return 0;
	}

	for (int i=0; i<Q; i++) {
		int L, R; ll X;
		cin >> L >> R >> X;
		for (int j=L; j<=R; j++) A[j] += X;
		cout << ans() << '\n';
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...