Trading
InterviewTime limit2sMemory limit64 MB
Each trader covers villages L to R with a price that rises by 1 per village, and each village reports the highest price ever asked there.
- Level
Medium4 of 10
- Topics
- Segment tree, Intervals
- Solved
- No attempts yet
Problem
There are villages beside the highway between Almaty and Taraz, numbered 1 to . When winter began, traders started selling knitted hats in these villages. Every trader keeps two rules: he trades in one village for a single day, and he raises his price every day.
Trader behaves like this.
- He starts trading in village at price .
- Every day he moves to the next village. If he traded in village yesterday, he trades in village today.
- Every day he raises the price by 1. If yesterday's price was , today's price is .
- He stops once he has sold his hats in village .
For each village, find the highest price that was ever asked there.
Input
The first line contains the number of villages and the number of traders (, ).
Each of the next lines contains three integers , , (, ): the first village, the last village, and the starting price of trader , in that order.
Output
Print integers on one line, separated by single spaces. The -th number is the highest price ever asked in village . Print 0 for a village where nobody traded.