After each range add to altitudes, report the wind temperature at spot N, where the total depends on the altitude differences between adjacent spots.
Medium6ArrayPrefix sumImplementationInterviewNo attempts yetTime limit1sMemory limit256 MBIn the Kingdom of IOI, the wind always blows from the sea toward the land. There are N+1 spots, numbered from 0 to N. The wind blows from Spot 0 to Spot N in order of their numbers. Mr. JOI has a house at Spot N. The altitude of Spot 0 is A0=0, and the altitude of Spot i (1≤i≤N) is Ai.
The wind blows along the surface of the ground, and its temperature changes as the altitude changes. At Spot 0, which is closest to the sea, the temperature of the wind is 0 degrees. For each i (0≤i≤N−1), the change in the temperature of the wind from Spot i to Spot i+1 depends only on Ai and Ai+1, as follows.
Tectonic movement is active in the land of the Kingdom of IOI. You are given the record of tectonic movements over Q days. On day j (1≤j≤Q), the altitude of every Spot k with Lj≤k≤Rj changes by Xj (1≤Lj≤Rj≤N). If Xj is not negative, the altitude increases by Xj. If Xj is negative, the altitude decreases by ∣Xj∣. Each tectonic movement applies to the altitudes left by the movements of the previous days.
Given the record of tectonic movements, write a program that computes, for each j (1≤j≤Q), the temperature of the wind at Mr. JOI's house right after the tectonic movement on day j.
The first line contains four space-separated integers N, Q, S, and T. Mr. JOI's house is at Spot N, and there are Q tectonic movements. When the altitude rises, the temperature of the wind decreases by S degrees per unit of altitude. When the altitude falls, it increases by T degrees per unit of altitude.
The i-th of the next N+1 lines (1≤i≤N+1) contains an integer Ai−1, the altitude of Spot (i−1) before any tectonic movement.
The j-th of the next Q lines (1≤j≤Q) contains three space-separated integers Lj, Rj, and Xj. They mean that on day j the altitude of the spots from Lj to Rj changes by Xj.
Print Q lines. The j-th line (1≤j≤Q) contains the temperature of the wind at Mr. JOI's house right after the tectonic movement on day j.