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 <iostream>
#include <vector>
//#define FEEDBACK
using namespace std;
typedef long long ll;
int main()
{
int n, q;
ll s, t;
cin >> n >> q >> s >> t;
s *= -1;
vector<ll> vec(n);
ll l1, l2;
cin >> l1;
ll temp = 0;
for(int i = 0; i < n; ++i){
cin >> l2;
vec[i] = l1-l2;
if(vec[i] < 0){
temp -= vec[i]*s;
}
else{
temp += vec[i]*t;
}
l1 = l2;
}
#ifdef FEEDBACK
for(int i = 0; i < n; ++i){
cout << vec[i] << " ";
}
cout << endl;
cout << "temp = " << temp << endl;
#endif // FEEDBACK
int l, k;
ll x, y;
vector<ll> res(q);
bool b1, b2;
for(int i = 0; i < q; ++i){
cin >> l >> k >> x;
--l;
b1 = vec[l] < 0;
y = vec[l];
vec[l] -= x;
b2 = vec[l] < 0;
if(b1 != b2){
if(b1){
temp += y*s;
temp += vec[l]*t;
}
else{
temp -= y*t;
temp -= vec[l]*s;
}
}
else{
if(b1){
temp += (y-vec[l])*s;
}
else{
temp -= (y-vec[l])*t;
}
}
if(k < n){
b1 = vec[k] < 0;
y = vec[k];
vec[k] += x;
b2 = vec[k] < 0;
if(b1 == !b2){
if(b1){
temp += y*s;
temp += vec[k]*t;
}
else{
temp -= y*t;
temp -= vec[k]*s;
}
}
else{
if(b1){
temp += (y-vec[k])*s;
}
else{
temp -= (y-vec[k])*t;
}
}
}
res[i] = temp;
#ifdef FEEDBACK
for(int i = 0; i < n; ++i){
cout << vec[i] << " ";
}
cout << endl;
cout << "temp = " << temp << endl;
#endif // FEEDBACK
}
for(int i = 0; i < q; ++i){
cout << res[i] << endl;
}
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... |