luogu#P3655. 不成熟的梦想家 (未熟 DREAMER)

不成熟的梦想家 (未熟 DREAMER)

Background

What kind of future it is, nobody knows yet.

But it should be fun.

If we’re all together, we can overcome anything.

It’s just the beginning—let’s encourage each other.

What kind of future it is, nobody knows yet.

But I really hope it will be full of fun.

If we’re all together, we’ll even want to push our limits.

I want to grow—I’m still just an immature DREAMER.

The members of Aqours have finally gathered.

Today is our very first concert with everyone together.

Everyone has practiced well; I’m sure we’ll perform great.

However, everyone’s singing skills should be as close as possible. If someone is too outstanding or too far behind, it will affect the performance.

So we borrowed an invention from the neighboring Academy City that can change our members’ singing skills.

Problem Description

There are N+1N+1 members in Aqours, lined up in a row.

Their singing skills are denoted by A[0]A[0] to A[N]A[N], and all A[i]A[i] for 0iN0 \le i \le N are given.

The machine from Academy City can change the singing skills of a consecutive segment in the line by adding a number ZZ to each of them. Of course, if ZZ is negative, it means subtracting.

I plan to use this machine QQ times. Each time, I add ZZ to the singing skills of all members from index XX to index YY (with 1X,Y1061 \le X, Y \le 10^6).

Our team’s charm value BB is computed as follows:

Initially, B=0B = 0. Then, for members from index 11 to NN:

  • If Ai1<AiA_{i-1} < A_i: B=BSAi1AiB = B - S \cdot |A_{i-1} - A_i|.
  • If Ai1>AiA_{i-1} > A_i: B=B+TAi1AiB = B + T \cdot |A_{i-1} - A_i|.

Here SS and TT are constants given by the Love Live committee.

As the leader, I (Chika) am always at the front of the line, with singing skill always 00. The machine will never modify me. Thus A0=0A_0 = 0 at all times.

Can you help us compute the charm value BB after each use of the machine?

Input Format

  • The first line contains four integers NN, QQ, SS, TT (as described above).
  • The next N+1N+1 lines each contain one integer AiA_i, with A0=0A_0 = 0.
  • The next QQ lines each contain three integers XX, YY, ZZ (as described above).

Output Format

Output QQ integers, one per line, where the ii-th line is the value of BB after the ii-th operation.

4 3 2 3
0
5
2
4
6
1 2 1
3 4 -3
1 4 2

-9
-1
-5

Hint

  • For 30% of the testdata, N,Q2000N, Q \le 2000.
  • Additionally, for another 20% of the testdata, S=TS = T.
  • For 100% of the testdata, N,Q200000N, Q \le 200000; 1S,T,Ai1061 \le S, T, A_i \le 10^6; Z106|Z| \le 10^6.
  • Note that a 64-bit integer may be required, and using std::cin/std::cout may time out.

Explanation of the sample:

After the first change,

A: 0 6 3 4 6

B: -12 -3 -5 -9

Easter egg:

None.

Why would there be so many easter eggs?

Translated by ChatGPT 5