This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#undef NDEBUG
#ifdef NDEBUG
#define dbg(TXTMSG) if constexpr (false) cerr << "lol"
#define dbgv(VARN) ((void)0)
#define dbgfor(COND) if constexpr (false) for (COND)
#else
#define _GLIBCXX_DEBUG 1
#define _GLIBCXX_DEBUG_PEDANTIC 1
#pragma GCC optimize("trapv")
#define dbg(TXTMSG) cerr << "\n" << TXTMSG
#define dbgv(VARN) cerr << "\n" << #VARN << " = "<< VARN << ", line: " << __LINE__ << "\n"
#define dbgfor(COND) for (COND)
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
#define e0 first
#define e1 second
constexpr ll INFTY = 2e18;
int main()
{
ll N,Q,S,T;
cin >> N >> Q >> S >> T;
S *= -1;
T *= -1;
vector<ll> A(N+1);
for (ll i = 0; i < N+1; ++i)
{
cin >> A[i];
}
vector<ll> pdiff(N);
ll currans=0;
for (ll i = 0; i < N; ++i)
{
pdiff[i]=A[i+1]-A[i];
if (pdiff[i]>0)
{
currans += S*pdiff[i];
}
else {
currans += T*pdiff[i];
}
}
dbg("h");
for (ll qno = 0; qno < Q; qno++)
{
ll L, R , X;
cin >> L >> R >> X;
dbg(L << " " << R << " " << X);
if (pdiff[L-1]>0)
{
currans -= S*pdiff[L-1];
}
else {
currans -= T*pdiff[L-1];
}
if (R<N){
if (pdiff[R]>0)
{
currans -= S*pdiff[R];
}
else {
currans -= T*pdiff[R];
}}
pdiff[L-1] += X;
if (R<N) pdiff[R] -= X;
if (pdiff[L-1]>0)
{
currans += S*pdiff[L-1];
}
else {
currans += T*pdiff[L-1];
}
if (R<N){
if (pdiff[R]>0)
{
currans += S*pdiff[R];
}
else {
currans += T*pdiff[R];
}}
cout << currans << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |