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>
using namespace std;
#define int long long
const int N = 2e5+5;
int n, q, s, t;
int l, r, val, sum_neg, sum_pos;
int a[N], diff[N];
void update(int i, int val)
{
if (i < 0 || i >= n) return;
if (diff[i] > 0 && diff[i] + val >= 0)
{
sum_pos += val;
}
else if (diff[i] > 0 && diff[i] + val < 0)
{
sum_pos -= diff[i];
sum_neg += (diff[i]+val);
}
else if (diff[i] <= 0 && diff[i]+val >= 0)
{
sum_neg -= diff[i];
sum_pos += diff[i]+val;
}
else if (diff[i] <= 0 && diff[i] + val < 0)
{
sum_neg += val;
}
diff[i] += val;
}
signed main()
{
cin >> n >> q >> s >> t;
for (int i = 0; i <= n; i++)
{
cin >> a[i];
}
for (int i = 0; i < n; i++)
{
diff[i] = a[i] - a[i+1];
if (diff[i] < 0)
sum_neg += diff[i];
else
sum_pos += diff[i];
}
while(q--)
{
cin >> l >> r >> val;
update(l-1,-val);
update(r,val);
cout << sum_neg*s + sum_pos*t << 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... |