Submission #655727

#TimeUsernameProblemLanguageResultExecution timeMemory
655727benjaminkleynFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
98 ms7500 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int N, Q; ll S, T, A[300001], D[300000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> N >> Q >> S >> T; cin >> A[0]; for (int i = 0; i < N; i++) { cin >> A[i + 1]; D[i] = A[i + 1] - A[i]; } ll res = 0; for (int i = 0; i < N; i++) res += max(0LL, -D[i]) * T - max(0LL, D[i]) * S; int L, R; ll x; while (Q--) { cin >> L >> R >> x; res -= max(0LL, -D[L-1]) * T - max(0LL, D[L-1]) * S; if (R != N) res -= max(0LL, -D[R]) * T - max(0LL, D[R]) * S; D[R] -= x; D[L-1] += x; res += max(0LL, -D[L-1]) * T - max(0LL, D[L-1]) * S; if (R != N) res += max(0LL, -D[R]) * T - max(0LL, D[R]) * S; cout << res << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...