# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
129297 | MrUnknown | Foehn Phenomena (JOI17_foehn_phenomena) | C++11 | 181 ms | 7292 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.
/***
* __ __ _ _ _
* | \/ | | | | | | |
* | \ / |_ __ | | | |_ __ | | ___ __ _____ ___ __
* | |\/| | '__| | | | | '_ \| |/ / '_ \ / _ \ \ /\ / / '_ \
* | | | | | _ | |__| | | | | <| | | | (_) \ V V /| | | |
* |_| |_|_| (_) \____/|_| |_|_|\_\_| |_|\___/ \_/\_/ |_| |_|
*
*
***/
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for (int i=a;i<=b;i++)
#define f_(i,a,b) for (int i=a;i>=b;i--)
#define MP make_pair
#define ii pair<int,int>
#define iii pair<int,ii>
const ll mod=1000000007;
int n,q;
ll s,t,a[200005],hieu[200005],tong=0;
int main() {
// freopen("","r",stdin);
// freopen("","w",stdout);
scanf("%d %d %lld %lld", &n, &q, &s, &t);
f(i,0,n) {
scanf("%lld", &a[i]);
if (i>0) hieu[i]=a[i]-a[i-1];
if (hieu[i]>=0) tong-=s*hieu[i];
else tong-=t*hieu[i];
}
// f(i,0,n) cout<<a[i]<<" ";
// cout<<"\n";
// cout<<"!"<<tong<<"\n";
// cout<<"check: ";
// f(i,1,n) cout<<hieu[i]<<" ";
// cout<<"\n";
while (q--) {
int l,r;
ll x;
scanf("%d %d %lld", &l, &r, &x);
if (l!=0) {
if (hieu[l]>=0) tong+=s*hieu[l];
else tong+=t*hieu[l];
}
if (r!=n) {
if (hieu[r+1]>=0) tong+=s*hieu[r+1];
else tong+=t*hieu[r+1];
}
// cout<<" "<<tong<<" "<<hieu[l]<<" "<<hieu[r+1]<<"\n";
if (l!=0) hieu[l]+=x;
if (r!=n) hieu[r+1]-=x;
// cout<<"check: ";
// f(i,1,n) cout<<hieu[i]<<" ";
// cout<<"\n";
// cout<<" "<<tong<<" "<<hieu[l]<<" "<<hieu[r+1]<<" ";
if (l!=0) {
if (hieu[l]>=0) tong-=s*hieu[l];
else tong-=t*hieu[l];
}
if (r!=n) {
if (hieu[r+1]>=0) tong-=s*hieu[r+1];
else tong-=t*hieu[r+1];
}
printf("%lld\n", tong);
}
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... |