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>
using namespace std;
using ll = long long;
struct FT{
vector<ll> ft;
int n;
FT(int n) : n(n),ft(n+1){};
void upd(int idx,int val){
for(; idx <= n; idx += idx & -idx){
ft[idx] += val;
}
}
ll qry(int idx){
ll sum = 0;
for(; idx > 0; idx -= idx & -idx){
sum += ft[idx];
}
return sum;
}
};
int main(){
int n,q,s,t;
cin >> n >> q >> s >> t;
auto f = [&](ll a,ll b){
if(a < b) return (b - a) * s * -1;
return (a - b) * t;
};
FT ft(n);
int prv = 0;
ll ans = 0;
for(int i = 0; i <= n; i++){
int x;
cin >> x;
if(i){
ans += f(prv,x);
ft.upd(i,x);
ft.upd(i + 1,-x);
}
prv = x;
}
while(q--){
int l,r,x;
cin >> l >> r >> x;
ans -= f(ft.qry(l-1),ft.qry(l));
if(r != n){
ans -= f(ft.qry(r),ft.qry(r+1));
}
ft.upd(l,x);
ft.upd(r + 1,-x);
ans += f(ft.qry(l-1),ft.qry(l));
if(r != n){
ans += f(ft.qry(r),ft.qry(r+1));
}
cout << ans << '\n';
}
}
Compilation message (stderr)
foehn_phenomena.cpp: In constructor 'FT::FT(int)':
foehn_phenomena.cpp:7:9: warning: 'FT::n' will be initialized after [-Wreorder]
7 | int n;
| ^
foehn_phenomena.cpp:6:16: warning: 'std::vector<long long int> FT::ft' [-Wreorder]
6 | vector<ll> ft;
| ^~
foehn_phenomena.cpp:8:5: warning: when initialized here [-Wreorder]
8 | FT(int n) : n(n),ft(n+1){};
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |