This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*huypheu
2 2 5 5
0
6
-1
1 1 4
1 2 8
*/
// https://oj.uz/problem/view/JOI17_foehn_phenomena
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[2000007],h[2000007];
signed main()
{
int n,q,s,t;
cin >> n >> q >> s >> t;
for(int i=0;i<=n;i++)
{
cin >> h[i];
if(i>=1) a[i]=h[i]-h[i-1];
}
int ans=0;
for(int i=1;i<=n;i++)
{
if(a[i]>0) ans-=a[i]*s; else ans-=a[i]*t;
}
for(int i=1;i<=q;i++)
{
int l,r,x;
cin >> l >> r >> x;
if(l!=0)
{
if(r!=n)
{
if(a[l]>0) ans+=a[l]*s; else ans+=a[l]*t;
if(a[r+1]>0) ans+=a[r+1]*s; else ans+=a[r+1]*t;
a[l]+=x;
a[r+1]-=x;
if(a[l]>0) ans-=a[l]*s; else ans-=a[l]*t;
if(a[r+1]>0) ans-=a[r+1]*s; else ans-=a[r+1]*t;
}
else
{
if(a[l]>0) ans+=a[l]*s; else ans+=a[l]*t;
a[l]+=x;
if(a[l]>0) ans-=a[l]*s; else ans-=a[l]*t;
}
}
else
{
if(r!=n)
{
if(a[r+1]>0) ans+=a[r+1]*s; else ans+=a[r+1]*t;
a[r+1]-=x;
if(a[r+1]>0) ans-=a[r+1]*s; else ans-=a[r+1]*t;
}
else
{
}
}
cout << ans << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |