Foehn Phenomena
InterviewTime limit1sMemory limit256 MB
After each range add to altitudes, report the wind temperature at spot N, where the total depends on the altitude differences between adjacent spots.
- Level
Medium6 of 10
- Topics
- Array, Prefix sum, Implementation
- Solved
- No attempts yet
Problem
In the Kingdom of IOI, the wind always blows from the sea toward the land. There are spots, numbered from 0 to . The wind blows from Spot 0 to Spot in order of their numbers. Mr. JOI has a house at Spot . The altitude of Spot 0 is , and the altitude of Spot () is .
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 (), the change in the temperature of the wind from Spot to Spot depends only on and , as follows.
- If , the temperature of the wind decreases by degrees per unit of altitude, that is, by degrees.
- If , the temperature of the wind increases by degrees per unit of altitude, that is, by degrees.
Tectonic movement is active in the land of the Kingdom of IOI. You are given the record of tectonic movements over days. On day (), the altitude of every Spot with changes by (). If is not negative, the altitude increases by . If is negative, the altitude decreases by . 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 (), the temperature of the wind at Mr. JOI's house right after the tectonic movement on day .
Input
The first line contains four space-separated integers , , , and . Mr. JOI's house is at Spot , and there are tectonic movements. When the altitude rises, the temperature of the wind decreases by degrees per unit of altitude. When the altitude falls, it increases by degrees per unit of altitude.
The -th of the next lines () contains an integer , the altitude of Spot before any tectonic movement.
The -th of the next lines () contains three space-separated integers , , and . They mean that on day the altitude of the spots from to changes by .
Output
Print lines. The -th line () contains the temperature of the wind at Mr. JOI's house right after the tectonic movement on day .
Constraints
- ()
- ()
- ()
- All input values are integers.