Submission #51522

#TimeUsernameProblemLanguageResultExecution timeMemory
51522huynhsmdFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
718 ms7724 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int N = 200005; int n , q , s , t , ans; int a[N] , bit[N]; signed main(){ //freopen("1.inp","r",stdin); cin >> n >> q >> s >> t; n++; for(int i = 1 ; i <= n ; ++ i) cin >> a[i]; for(int i = 2; i <= n ; i ++){ bit[i] = a[i] - a[i - 1]; if (bit[i] >= 0) ans -= bit[i] * s; else ans -= bit[i] * t; } while(q--){ int l , r , val; cin >> l >> r >> val; l++ ; r++; if (bit[l] >= 0) ans += bit[l] * s; else ans += bit[l] * t; bit[l] += val; if (bit[l] >= 0) ans -= bit[l] * s; else ans -= bit[l] * t; if (r != n) { if (bit[r + 1] >= 0) ans += bit[r + 1] * s; else ans += bit[r + 1] * t; bit[r + 1] -= val; if (bit[r + 1] >= 0) ans -= bit[r + 1] * s; else ans -= bit[r + 1] * t; } cout << ans <<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...