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
int main () {
int n,q,s,t;
cin >> n >> q >> s >> t;
int high[n];
int x = 0, y = 0;
for (int i=0;i<=n;i++) {
int temp;
cin >> temp;
high[i] = temp;
if (i>0) {
if (temp>high[i-1]) {x += temp - high[i-1];}
if (temp<high[i-1]) {y += high[i-1] - temp;}
}
}
int suhu = x*(-s) + y*t;
for (int i=0;i<q;i++) {
int l,r,j;
cin >> l >> r >> j;
int ltemp = high[l] + j;
int rtemp = high[r] + j;
int jtemp = j;
if (j<0) j *= -1;
if (high[l] < high[l-1]) {
if (ltemp > high[l-1]) {
x += ltemp - high[l-1];
y -= j - (ltemp - high[l-1]);
} else if (ltemp < high[l-1]) {
if (high[l-1]-high[l] > high[l-1]-ltemp) {
y -= j;
} else y += j;
} else {
y -= j;
}
}
if (high[l] > high[l-1]) {
if (ltemp < high[l-1]) {
x -= j - (high[l-1] - ltemp);
y += high[l-1] - ltemp;
} else if (ltemp > high[l-1]) {
if (high[l]-high[l-1] > ltemp-high[l-1]) {
x -= j;
} else x += j;
} else {
x -= j;
}
}
if (r!=n) {
if (high[r] < high[r+1]) {
if (rtemp > high[r+1]) {
x -= j - (rtemp - high[r+1]);
y += rtemp - high[r+1];
} else if (rtemp < high[r+1]) {
if (high[r+1]-high[r] > high[r+1]-rtemp) {
x -= j;
} else x += j;
} else {
x -= j;
}
}
if (high[r] > high[r+1]) {
if (rtemp < high[r+1]) {
x += high[r+1] - rtemp;
y -= j - (high[r+1] - rtemp);
} else if (rtemp > high[r+1]){
if (high[r]-high[r+1] > rtemp-high[r+1]) {
y -= j;
} else y += j;
} else {
y -= j;
}
}
}
suhu = x*(-s) + y*t;
cout << suhu << endl;
for (int a=l;a<=r;a++) {
high[a] += jtemp;
}
}
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... |