#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";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
348 KB |
Output is correct |
2 |
Correct |
17 ms |
348 KB |
Output is correct |
3 |
Correct |
20 ms |
348 KB |
Output is correct |
4 |
Correct |
18 ms |
348 KB |
Output is correct |
5 |
Correct |
18 ms |
348 KB |
Output is correct |
6 |
Correct |
18 ms |
348 KB |
Output is correct |
7 |
Correct |
18 ms |
344 KB |
Output is correct |
8 |
Correct |
22 ms |
348 KB |
Output is correct |
9 |
Correct |
18 ms |
524 KB |
Output is correct |
10 |
Correct |
17 ms |
348 KB |
Output is correct |
11 |
Correct |
18 ms |
520 KB |
Output is correct |
12 |
Correct |
18 ms |
556 KB |
Output is correct |
13 |
Correct |
18 ms |
348 KB |
Output is correct |
14 |
Correct |
18 ms |
348 KB |
Output is correct |
15 |
Correct |
17 ms |
348 KB |
Output is correct |
16 |
Correct |
17 ms |
348 KB |
Output is correct |
17 |
Correct |
17 ms |
348 KB |
Output is correct |
18 |
Correct |
17 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1073 ms |
10848 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
348 KB |
Output is correct |
2 |
Correct |
17 ms |
348 KB |
Output is correct |
3 |
Correct |
20 ms |
348 KB |
Output is correct |
4 |
Correct |
18 ms |
348 KB |
Output is correct |
5 |
Correct |
18 ms |
348 KB |
Output is correct |
6 |
Correct |
18 ms |
348 KB |
Output is correct |
7 |
Correct |
18 ms |
344 KB |
Output is correct |
8 |
Correct |
22 ms |
348 KB |
Output is correct |
9 |
Correct |
18 ms |
524 KB |
Output is correct |
10 |
Correct |
17 ms |
348 KB |
Output is correct |
11 |
Correct |
18 ms |
520 KB |
Output is correct |
12 |
Correct |
18 ms |
556 KB |
Output is correct |
13 |
Correct |
18 ms |
348 KB |
Output is correct |
14 |
Correct |
18 ms |
348 KB |
Output is correct |
15 |
Correct |
17 ms |
348 KB |
Output is correct |
16 |
Correct |
17 ms |
348 KB |
Output is correct |
17 |
Correct |
17 ms |
348 KB |
Output is correct |
18 |
Correct |
17 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Execution timed out |
1073 ms |
10848 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |