# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1159986 | hainam2k9 | Foehn Phenomena (JOI17_foehn_phenomena) | C++20 | 95 ms | 6472 KiB |
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 2e5+5;
const string NAME = "";
int n,q,s,t,a[MAXN];
ll bit[MAXN],cur=0;
void update(int pos, int val){
while(pos<=n) bit[pos]+=val, pos+=pos&-pos;
}
ll sum(int pos){
ll rs=0;
while(pos>0) rs+=bit[pos], pos-=pos&-pos;
return rs;
}
ll cost(ll L, ll R){
if(L<R) return -s*(R-L);
return t*(L-R);
}
int main()
{
tt;
if(fopen((NAME + ".INP").c_str(), "r")) fo;
cin >> n >> q >> s >> t;
for(int i = 0; i<=n; ++i){
cin >> a[i];
if(i==0) continue;
update(i,a[i]-a[i-1]);
cur+=cost(a[i-1],a[i]);
}
while(q--){
int l,r,x;
cin >> l >> r >> x;
cur-=cost(sum(l-1),sum(l));
if(r<n) cur-=cost(sum(r),sum(r+1));
update(l,x), update(r+1,-x);
cur+=cost(sum(l-1),sum(l));
if(r<n) cur+=cost(sum(r),sum(r+1));
cout << cur << "\n";
}
}
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... |