# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
926881 | haru09 | Foehn Phenomena (JOI17_foehn_phenomena) | C++17 | 111 ms | 12560 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
#define fi first
#define se second
#define task "code"
const int ar=2e5+5;
const ll mod=1e9+7;
int n,q,s,t;
int a[ar];
ll ans=0;
ll bit[ar];
void update(int u,int v)
{
int id=u;
while(id<=n+1)
{
bit[id]+=v;
id+=id&(-id);
}
}
ll get(int p)
{
int id=p;
ll ans=0;
while(id>0)
{
ans+=bit[id];
id-=id&(-id);
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
if (fopen(task".inp","r"))
{
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin>>n>>q>>s>>t;
for (int i=0;i<=n;i++)
{
cin>>a[i];
if (i) update(i,a[i]),update(i+1,-a[i]);
}
for (int i=1;i<=n;i++)
{
if (a[i]>a[i-1]) ans-=1ll*s*(a[i]-a[i-1]);
else ans+=1ll*t*(a[i-1]-a[i]);
}
while(q--)
{
int l,r,x;
ll val1,val2;
cin>>l>>r>>x;
val1=get(l);
val2=get(l-1);
if (val1>val2) ans+=(val1-val2)*s;
else ans-=(val2-val1)*t;
if (r<n)
{
val1=get(r+1);
val2=get(r);
if (val1>val2) ans+=(val1-val2)*s;
else ans-=(val2-val1)*t;
}
update(l,x);
update(r+1,-x);
val1=get(l);
val2=get(l-1);
if (val1>val2) ans-=(val1-val2)*s;
else ans+=(val2-val1)*t;
if (r<n)
{
val1=get(r+1);
val2=get(r);
if (val1>val2) ans-=(val1-val2)*s;
else ans+=(val2-val1)*t;
}
cout<<ans<<'\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... |