# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1232824 | Bui_Quoc_Cuong | Foehn Phenomena (JOI17_foehn_phenomena) | C++20 | 90 ms | 5188 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) A.begin(), A.end()
#define SZ(A) (int)A.size()
#define FOR(i, a, b) for(int i = a; i <= (int)b; i++)
#define FORD(i, a, b) for(int i = a; i >= (int)b; i--)
#define fi first
#define se second
#define pb push_back
const int N = 3e5 + 5;
int n, q, s, t;
int a[N];
long long bit[N];
void update(int u, int val){
for(int i = u; i <= n; i+=i&-i)
bit[i]+= val;
}
void uprange(int l, int r, int val){
update(l, val);
update(r + 1, - val);
}
long long get(int u){
long long sum = 0;
for(int i = u; i > 0; i-=i&-i) sum+= bit[i];
return sum;
}
void process(){
cin >> n >> q >> s >> t;
FOR(i, 0, n) cin >> a[i];
FOR(i, 1, n) uprange(i, i, a[i]);
long long ans = 0;
FOR(i, 0, n - 1){
if(a[i] < a[i + 1]) ans-= 1LL * s * (a[i + 1] - a[i]);
else ans+= 1LL * t * (a[i] - a[i + 1]);
}
while(q--){
int l, r, x; cin >> l >> r >> x;
int hl = get(l), hr = get(r);
if(get(l - 1) < hl){
ans+= 1LL * s * (hl - get(l - 1));
} else ans-= 1LL * t * (get(l - 1) - hl);
if(r < n){
if(hr < get(r + 1)) ans+= 1LL * s * (get(r + 1) - hr);
else ans-= 1LL * t * (hr - get(r + 1));
}
uprange(l, r, x);
hl = get(l), hr = get(r);
if(get(l - 1) < hl){
ans-= 1LL * s * (hl - get(l - 1));
} else ans+= 1LL * t * (get(l - 1) - hl);
if(r < n){
if(hr < get(r + 1)) ans-= 1LL * s * (get(r + 1) - hr);
else ans+= 1LL * t * (hr - get(r + 1));
}
cout << ans << "\n";
}
}
signed main(void){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#define taskname "kieuoanh"
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout);
}
process();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |