이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q, s, t;
cin >> n >> q >> s >> t;
vector<int64_t> amplitudes;
int64_t temps[n + 1] = {0};
int l, r, x, a = 0;
cin >> x;
a = x;
amplitudes.push_back(x);
for(int i = 1; i <= n; i++){
cin >> x;
amplitudes.push_back(x - a);
a = x;
}
temps[0] = 0;
for(int i = 1; i <= n; i++){
if(amplitudes[i] < 0){
temps[i] = temps[i - 1] - t * amplitudes[i];
}else{
temps[i] = temps[i - 1] - s * amplitudes[i];
}
}
for(int k = 0; k < q; k++){
cin >> l >> r >> x;
if(x > 0){
if(amplitudes[l] >= 0){
temps[n] -= x * s;
}else if(amplitudes[l] > -x){
temps[n] -= (-amplitudes[l] * t + (x + amplitudes[l]) * s);
}else{
temps[n] -= x * t;
}
if(r < n){
if(amplitudes[r + 1] <= 0){
temps[n] += x * t;
}else if(amplitudes[r + 1] < x){
temps[n] += amplitudes[r + 1] * s + (x - amplitudes[r + 1]) * t;
}else{
temps[n] += x * s;
}
}
}else{
if(amplitudes[l] <= 0){
temps[n] -= x * t;
}else if(amplitudes[l] <= -x){
temps[n] += (amplitudes[l] * s + (-x - amplitudes[l]) * t);
}else{
temps[n] -= x * s;
}
if(r < n){
if(amplitudes[r + 1] >= 0){
temps[n] += x * s;
}else if(amplitudes[r + 1] > x){
temps[n] -= -amplitudes[r + 1] * t - (-x + amplitudes[r + 1]) * s;
}else{
temps[n] += x * t;
}
}
}
amplitudes[l] += x;
amplitudes[r + 1] -= x;
cout << temps[n] << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |