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 int long long
using namespace std;
const int N = 2e5 + 1;
int n , q , S , T , sum = 0;
vector<int> A(N) , t(N);
void add(int u , int x){
while(u <= n){
t[u] += x;
u += u&-u;
}
}
int get(int u){
int s = 0;
while(u > 0){
s += t[u];
u -= u&-u;
}
return s;
}
main(){
cin >> n >> q >> S >> T;
auto value = [&](int i){
return (A[i] > A[i - 1] ? -S * (A[i] - A[i - 1]) : T * (A[i - 1] - A[i]));
};
cin >> A[0];
for(int i = 1;i <= n;i ++){
cin >> A[i];
add(i , A[i]);
if(i < n){
add(i + 1 , -A[i]);
}
sum += value(i);
}
while(q--){
int l , r , x;
cin >> l >> r >> x;
add(l , x);
if(r + 1 < n){
add(r + 1 , -x);
}
if(r < n){
sum -= value(r + 1);
A[r] = get(r);
A[r + 1] = get(r + 1);
sum += value(r + 1);
}
sum -= value(l);
A[l] = get(l);
A[l - 1] = get(l - 1);
sum += value(l);
cout << sum << endl;
}
}
Compilation message (stderr)
foehn_phenomena.cpp:21:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
21 | 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... |