Submission #146596

#TimeUsernameProblemLanguageResultExecution timeMemory
146596wjoaoFoehn Phenomena (JOI17_foehn_phenomena)C++11
0 / 100
1055 ms7896 KiB
#include<bits/stdc++.h> #define maxn 200100 using namespace std; struct BIT{ int v[maxn]; void update(int x, int val){ for(; x < maxn; x += x&-x) v[x] += val; } void rangeupdate(int x, int y, int val){ update(x, val); update(y+1, -val); } int query(int x){ if( x <= 0 ) return 0; if( x >= maxn ) x = maxn-1; int sum = 0; for(; x > 0; x -= x&-x) sum += v[x]; return sum; } } bit; int n, q, s, t, res, anterior, atual, L, R, x; int calc(int a, int b){ if(a<b) return (a-b)*s; else return (a-b)*t; } int main(){ cin >> n >> q >> s >> t; n++; for(int i = 1; i <= n; i++){ cin >> atual; bit.rangeupdate(i, i, atual); res += calc(anterior, atual); anterior = atual; } for(int i = 1; i <= q; i++){ cin >> L >> R >> x; L++; R++; res -= calc(bit.query(L-1), bit.query(L)); if(R+1 <= n){ res -= calc(bit.query(R), bit.query(R+1)); } bit.rangeupdate(L, R, x); res += calc(bit.query(L-1), bit.query(L)); if(R+1 <= n){ res += calc(bit.query(R), bit.query(R+1)); } cout << res << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...