# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
33277 | huynd2001 | Foehn Phenomena (JOI17_foehn_phenomena) | C++14 | 196 ms | 9828 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.
/*huypheu
7 8 8 13
0
4
-9
4
-2
3
10
-9
1 4 8
3 5 -2
3 3 9
1 7 4
3 5 -1
5 6 3
4 4 9
6 7 -10
*/
// https://oj.uz/problem/view/JOI17_foehn_phenomena
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[200007],h[200007];
int la[200007],ra[200007],xa[200007];
signed main()
{
// ios_base::sync_with_stdio(false);
// cin.tie(0);
int n,q,s,t;
// cin >> n >> q >> s >> t;
// printf("lz");
scanf("%lld %lld %lld %lld",&n,&q,&s,&t);
for(int i=0;i<=n;i++)
{
// cin >> h[i];
scanf("%lld",&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++)
{
// cin >> la[i] >> ra[i] >> xa[i];
scanf("%lld %lld %lld",&la[i],&ra[i],&xa[i]);
}
// printf("lz");
for(int i=1;i<=q;i++)
{
int l,r,x;
l=la[i],r=ra[i],x=xa[i];
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;
printf("%lld\n",ans);
}
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... |