이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, q, s, t;
cin >> n >> q >> s >> t;
vector<ll> diff(n); // diff i sama i+1;
ll prev, now;
ll diffAll = 0;
cin >> prev;
for (int i = 0; i < n; i++)
{
cin >> now;
diff[i] = prev - now;
if (diff[i] <= 0)
{
diffAll += (diff[i] * s);
}
else
{
diffAll += (diff[i] * t);
}
prev = now;
}
// for (auto x : diff)
// {
// cout << x;
// }
for (int i = 0; i < q; i++)
{
ll l, r, x;
cin >> l >> r >> x;
if (l > 0)
{
if (diff[l - 1] <= 0)
{
diffAll -= diff[l - 1] * s;
}
else
{
diffAll -= diff[l - 1] * t;
}
diff[l - 1] -= x;
if (diff[l - 1] <= 0)
{
diffAll += diff[l - 1] * s;
}
else
{
diffAll += diff[l - 1] * t;
}
}
if (r < n)
{
if (diff[r] <= 0)
{
diffAll -= diff[r] * s;
}
else
{
diffAll -= diff[r] * t;
}
diff[r] += x;
if (diff[r] <= 0)
{
diffAll += diff[r] * s;
}
else
{
diffAll += diff[r] * t;
}
}
cout << diffAll << "\n";
}
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... |