This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define maxn 200100
#define int long long
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;
}
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;
}
Compilation message (stderr)
foehn_phenomena.cpp:35:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |