Dunes
InterviewTime limit2sMemory limit512 MB
Each gust adds +x to l and then alternates signs up to r; answer m queries for the final height at given positions.
- Level
Medium4 of 10
- Topics
- Array, Prefix sum, Implementation, Sorting
- Solved
- No attempts yet
Problem
The geographer Grigory Georgievich studies how sand dunes form. He picked a very long dune and divided it into a huge number of sections, numbered from 1 to .
Grigory Georgievich's theory states that initially the sand height at every section, measured from some reference level, was zero. After that, strong wind gusts blew, and each could change the terrain.
Gust number had strength and acted on the sections from to . As a result of this gust, the height of section increased by , the height of section decreased by , the next one increased again, and so on up to section , inclusive.
Knowing all the information about all gusts, Grigory Georgievich wants to find the final height of some sections that interest him. Help him.
Input
The first line of the input file contains two positive integers and (): the number of wind gusts and the number of sections whose final height interests Grigory Georgievich.
Each of the next lines contains a description of one wind gust: three integers (; ).
Each of the next lines contains an integer (): the number of the section whose final height must be found. The section numbers are given in increasing order.
Output
For each of the queries, output one integer: the height of the corresponding section.