CLFLARR - COLORFUL ARRAY

You have been given an array of n unpainted elements. By unpainted, we mean that each element initially has a value of 0. You have to process q queries of the form l r c, in which you paint all the elements of the array from index l to index r with color c. Assume that, each new color currently being applied to an element overrides its previous color. Output the color of each element after all the queries have been processed.

Note: The problem is guaranteed to be solved using C or C++ programming language.

Input

The first line of input consists of two integers n and q. Next q lines consists of 3 integers l, r and c denoting the starting index, ending index and the color respectively.

  • 1 <= n <= 200000
  • 1 <= q <= 200000
  • 1 <= l <= r <= n
  • 1 <= c <= 1 000 000 000

Output

Output the final color of each element starting from index 1 on a new line.

Example

Input:
4 3
1 3 2
2 4 6
2 3 7

Output:
2
7
7
6
Input:
10 5
3 9 13
1 4 9
2 10 14
2 7 10
6 9 44

Output:
9
10
10
10
10
44
44
44
44
14

Added by:No_idea
Date:2019-03-21
Time limit:2s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:Competitive Programming Community

hide comments
2020-08-05 01:43:29
AC in one go. SegTree with Lazy.
2020-07-09 19:49:59
Nice problem on DSU. Can be solved using segment trees too
2020-06-25 08:16:54
a beginner can benefit a lot from ths question!!
method 1 - segemnt trees + lazy update
method 2 - process query in reverse order and keep an additional array next which points to the next unpainted block
method 3 - do the same thing above but use DSU i.e. merge(i, i+1) and merge based on one with higher value of parent. i think 3 might be more efficient than 2 as the latter uses path compression along the way

Last edit: 2020-06-25 11:17:57
2020-05-29 18:40:24
please someone tell my mistake
2019-03-25 15:06:55
The note recommends you to submit a solution in C/C++ language, since efficient solutions in Java/Python and/or other slower/interpreted languages might not pass the 2 second time limit.
Update: Efficient Python solutions do get Accepted.

Last edit: 2019-04-02 16:05:09
2019-03-25 10:34:08 wisfaq
Can someone explain what is meant by:
Note: The problem is guaranteed to be solved using C or C++ programming language.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.