For each protected point, count how many starting mines eventually trigger a blast covering it, given chain reactions over intervals.
Hard8IntervalsSortingSegment treeGraphNo attempts yetTime limit3sMemory limit256 MBIn the year 12117, South Korea and North Korea declared unification in honor of Choi Seokhwan (gs12117), a great intellectual of the Korean Peninsula. General Lee Wonhyung of the Republic of Korea (no relation to the Lee Wonhyung born in 1998) is a great soldier in charge of his country's cyber defense. He is now working out how to clear the mines buried in the demilitarized zone.
The demilitarized zone is modeled as a number line from 0 to 109. Exactly N mines are buried in it, and mine i is at position Xi. A mine explodes when a disturbance is detected at its position Xi.
Many kinds of bombs are buried there, including nuclear mines and Galaxy Note 7s, so each mine explodes differently. Mine i explodes a distance Li to the left and Ri to the right, which means its blast range is the closed interval [Xi−Li,Xi+Ri]. Explosions set off chain reactions: if the position of a mine that has not exploded yet lies inside a blast range, that mine explodes too.
General Lee plans to detonate one mine as a test. The demilitarized zone, however, is home to many cultural heritage sites and endangered animals, and the general wants to survey the area first to protect them as much as possible. He has designated M protected areas, and protected area j is at position Cj. For each protected area, he wants to know how many mines can destroy it. A mine can destroy a protected area if, when only that mine is detonated at the start, the protected area lies inside the blast range of at least one exploded mine once the chain reaction ends.
In his youth General Lee was a celebrated competitor in the Korea Olympiad in Informatics (KOI), but now he is far too busy preparing an address to the nation. Solve the problem for him.
The first line contains the number of mines N and the number of protected areas M. (1≤N≤106, 1≤M≤300000)
Each of the next N lines describes one mine. The i-th of these lines contains three integers Xi, Li, and Ri: the position of mine i and its blast distances to the left and to the right. (0≤Xi≤109, 1≤Li,Ri≤109)
Each of the next M lines contains one integer Cj, the position of protected area j. (0≤Cj≤109)
Print M lines. The j-th line contains the number of mines that can destroy protected area j.
In the example, no mine can destroy the protected area at position 101.
The protected area at position 100 is destroyed when mine 4 explodes. Detonating any one of mines 1, 2, and 4 at the start eventually makes mine 4 explode.
The protected area at position 0 is destroyed when mine 2 explodes. Mine 2 explodes only if mine 2 itself is detonated at the start.
The protected area at position 14 is destroyed when any of mines 1, 3, and 4 explodes. Whichever of mines 1 to 4 is detonated at the start, one of these three mines explodes. So the protected area is destroyed no matter which mine is detonated.