제출 #848495

#제출 시각아이디문제언어결과실행 시간메모리
848495n3rm1nFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
92 ms13136 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; const long long MAXN = 2e5 + 10; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } long long n, q, s, t; long long a[MAXN]; void read_array() { cin >> n >> q >> s >> t; for (long long i = 0; i <= n; ++ i) cin >> a[i]; } long long p[MAXN]; long long ans = 0; void precompute() { for (long long i = 1; i <= n; ++ i) { p[i] = a[i] - a[i-1]; if(p[i] > 0)ans -= s * abs(p[i]); else ans += t * abs(p[i]); } } void solve() { long long left, right, x; while(q --) { cin >> left >> right >> x; if(p[left] > 0)ans += s * abs(p[left]); else ans -= t * abs(p[left]); p[left] += x; if(p[left] > 0)ans -= s * abs(p[left]); else ans += t * abs(p[left]); if(right != n) { if(p[right+1] > 0)ans += s * abs(p[right+1]); else ans -= t * abs(p[right+1]); p[right+1] -= x; if(p[right+1] > 0)ans -= s * abs(p[right + 1]); else ans += t * abs(p[right + 1]); } cout << ans << endl; } } int main() { speed(); read_array(); precompute(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...