# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
209266 | jzh | Foehn Phenomena (JOI17_foehn_phenomena) | C++14 | 165 ms | 7416 KiB |
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;
typedef long long ll;
ll ft[2000005];
ll ls(ll x) {
return (x & (-x));
}
ll query(ll p) {
ll sum = 0;
for(; p; p -= ls(p)) sum += ft[p];
return sum;
}
void update(ll x, ll y, ll v) {
for(; x < 2000005; x += ls(x)) ft[x] += v;
y++;
for(; y < 2000005; y += ls(x)) ft[y] -= v;}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,q,i,s,t,i1,x,y,w,sum=0,xi,yi;
cin>>n>>q>>s>>t;
ll arr[n+1];
for (i=0;i<=n;i++){
cin>>arr[i];
if (i>0)update(i,i,arr[i]);
}
for (i=1;i<=n;i++){
if (arr[i]>arr[i-1])sum-=s*(arr[i]-arr[i-1]);
else sum+=t*(arr[i-1]-arr[i]);
}
//cout<<sum<<'\n';
//cout<<query(0)<<'\n';
while (q--){
cin>>x>>y>>w;
xi=query(x)-query(x-1);
if (y!=n)yi=query(y+1)-query(y);
else yi=0;
if (xi>0)sum+=s*xi;
else sum+=t*xi;
if (yi>0)sum+=s*yi;
else sum+=t*yi;
update(x,y,w);
xi=query(x)-query(x-1);
if (y!=n)yi=query(y+1)-query(y);
else yi=0;
if (xi>0)sum-=s*xi;
else sum-=t*xi;
if (yi>0)sum-=s*yi;
else sum-=t*yi;
cout<<sum<<'\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... |