# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
954155 | StefanSebez | Foehn Phenomena (JOI17_foehn_phenomena) | C++14 | 137 ms | 16892 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;
#define ll long long
const int N=3*1e5+500;
ll p[N+50];
void Update(int i,ll qval){
for(;i<=N;i+=i&(-i)) p[i]+=qval;
}
ll Get(int i){
ll sum=0;
for(;i>=1;i-=i&(-i)) sum+=p[i];
return sum;
}
//int Sum(int l,int r){return Get(r)-Get(l-1);}
int main()
{
int n,q;ll S,T;scanf("%i%i%lld%lld",&n,&q,&S,&T);
ll a[N+50];for(int i=0;i<=n;i++) scanf("%lld",&a[i]);
ll b[N+50],res=0;
for(int i=1;i<=n;i++){
if(a[i-1]<a[i]) b[i]=(a[i-1]-a[i])*S;
else b[i]=(a[i-1]-a[i])*T;
res+=b[i];
}
//printf("%i\n",res);
while(q--){
int l,r;ll x;scanf("%i%i%lld",&l,&r,&x);
Update(l,x);Update(r+1,-x);
ll temp=b[l],u=Get(l-1)+a[l-1],v=Get(l)+a[l];
if(u<v) b[l]=(u-v)*S;
else b[l]=(u-v)*T;
res+=b[l]-temp;
//printf("%i %i %i %i\n",u,v,temp,b[l]);
if(r+1<=n){
temp=b[r+1],u=Get(r)+a[r],v=Get(r+1)+a[r+1];
if(u<v) b[r+1]=(u-v)*S;
else b[r+1]=(u-v)*T;
res+=b[r+1]-temp;
}
printf("%lld\n",res);
}
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... |