# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
58919 | TadijaSebez | Foehn Phenomena (JOI17_foehn_phenomena) | C++11 | 363 ms | 52080 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 <stdio.h>
#define ll long long
const int N=200050;
struct BIT
{
ll sum[N],a[N];
void init(){ for(int i=0;i<N;i++) sum[i]=a[i]=0;}
void Set1(int i, ll x){ int j=i;for(;i<N;i+=i&-i) sum[i]+=x-a[j];a[j]=x;}
void Set2(int i, ll x){ for(i++;i<N;i+=i&-i) sum[i]+=x;}
void Set2(int l, int r, ll x){ Set2(l,x);Set2(r+1,-x);}
ll Get1(int i){ ll ret=0;for(;i;i-=i&-i) ret+=sum[i];return ret;}
ll Get2(int i){ return Get1(i+1);}
ll Get1(){ return Get1(N-1);}
} BIT1,BIT2;
int a[N],s,t;
ll abs(ll x){ return x>0?x:-x;}
ll Get(ll x, ll y)
{
return (ll)(x>y?-s:t)*abs(x-y);
}
int main()
{
int n,q,i;BIT1.init();BIT2.init();
scanf("%i %i %i %i",&n,&q,&s,&t);
for(i=0;i<=n;i++) scanf("%i",&a[i]),BIT2.Set2(i,i,a[i]);
for(i=1;i<=n;i++) BIT1.Set1(i,Get(a[i],a[i-1]));
int l,r,x;
while(q--)
{
scanf("%i %i %i",&l,&r,&x);
BIT2.Set2(l,r,x);
BIT1.Set1(l,Get(BIT2.Get2(l),BIT2.Get2(l-1)));
if(r!=n) BIT1.Set1(r+1,Get(BIT2.Get2(r+1),BIT2.Get2(r)));
printf("%lld\n",BIT1.Get1());
}
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... |