제출 #489063

#제출 시각아이디문제언어결과실행 시간메모리
489063cheissmartFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
105 ms12368 KiB
#include <bits/stdc++.h> #define IO_OP ios::sync_with_stdio(0), cin.tie(0) #define F first #define S second #define V vector #define PB push_back #define EB emaplce_back #define MP make_pair #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef vector<int> vi; const int INF = 1e9 + 7, N = 2e5 + 7; int a[N]; ll d[N]; signed main() { IO_OP; int n, q, s, t; cin >> n >> q >> s >> t; ll ans = 0; auto cost = [&] (ll x) { if(x > 0) return -x * s; else return -x * t; }; for(int i = 0; i < n + 1; i++) { cin >> a[i]; if(i) { d[i] = a[i] - a[i - 1]; ans += cost(d[i]); } } for(int i = 0; i < q; i++) { int l, r, x; cin >> l >> r >> x; // d[l] += x, d[r + 1] -= x ans -= cost(d[l]); d[l] += x; ans += cost(d[l]); if(r + 1 <= n) { ans -= cost(d[r + 1]); d[r + 1] -= x; ans += cost(d[r + 1]); } cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...