이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ioss ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
int n, q, s, t;
signed main() {
ioss;
cin >> n >> q >> s >> t;
int diffarr[n+3] = {}, tmp = 0;
for(int i = 0; i <= n; i++) {
int a; cin >> a;
if(i == 0) diffarr[i] = 0;
else diffarr[i] = a-tmp;
tmp = a;
}
int cntneg = 0, cntpos = 0;
for(int i = 0; i <= n; i++) {
if(diffarr[i] <= 0) cntneg += diffarr[i];
else cntpos += diffarr[i];
// cout << diffarr[i] << " ";
}
for(int i = 0; i < q; i++) {
int l, r, x;
cin >> l >> r >> x;
if(diffarr[l] <= 0) cntneg -= diffarr[l];
else cntpos -= diffarr[l];
if(r < n && diffarr[r+1] <= 0) cntneg -= diffarr[r+1];
else if(r < n) cntpos -= diffarr[r+1];
diffarr[l] += x, diffarr[r+1] -= x;
if(diffarr[l] <= 0) cntneg += diffarr[l];
else cntpos += diffarr[l];
if(r < n && diffarr[r+1] <= 0) cntneg += diffarr[r+1];
else if(r < n) cntpos += diffarr[r+1];
// cout << " :: " << diffarr[l] << " " << diffarr[r+1] << " " << abs(cntneg) << " " << (-cntpos) << endl;
cout << abs(cntneg)*t + (-cntpos)*s << 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... |