제출 #1172966

#제출 시각아이디문제언어결과실행 시간메모리
1172966nguyenkhangninh99Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
183 ms7400 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int maxn = 1e6 + 5; int a[maxn], pre[maxn]; void solve(){ int n, q, s, t; cin >> n >> q >> s >> t; for(int i = 0; i <= n; i++) cin >> a[i]; for(int i = 0; i <= n; i++){ pre[i] += a[i]; pre[i + 1] -= a[i]; } int sum1 = 0, sum2 = 0; for(int i = 1; i <= n; i++){ if (pre[i] > 0) sum1 += pre[i]; if (pre[i] < 0) sum2 -= pre[i]; } while (q--){ int x, y, z; cin >> x >> y >> z; if (pre[x] > 0) sum1 -= pre[x]; if (pre[x] < 0) sum2 += pre[x]; if (y + 1 <= n){ if (pre[y + 1] > 0) sum1 -= pre[y + 1]; if (pre[y + 1] < 0) sum2 += pre[y + 1]; } pre[x] += z; pre[y + 1] -= z; if (pre[x] > 0) sum1 += pre[x]; if (pre[x] < 0) sum2 -= pre[x]; if (y + 1 <= n){ if (pre[y + 1] > 0) sum1 += pre[y + 1]; if (pre[y + 1] < 0) sum2 -= pre[y + 1]; } cout << t*sum2-s*sum1 << endl; } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...