This page is still under construction.

Parts of this page are still being built. What you see may change.

Wall

Time limit3sMemory limit256 MB

Summary
Apply k range raise-to-at-least and lower-to-at-most updates on n columns and print each final height.
Level

Hard8 of 10

Topics
Segment tree
Solved
No attempts yet

Problem

Gianina builds a wall of nn columns of equal bricks. Columns are numbered 00 through n−1n-1 from left to right. The height of a column is its brick count.

Initially every column has height 0. Over kk steps, each step gives an inclusive column range [left,right][\text{left}, \text{right}] and a height hh.

  • Add (op=1): within the range, any column shorter than hh receives bricks until its height is exactly hh. Columns already at least hh stay unchanged.
  • Remove (op=2): within the range, any column taller than hh loses bricks until its height is exactly hh. Columns already at most hh stay unchanged.

After all steps, output the final brick count in each column.

Input

Line 1: nn, kk.

Next kk lines: op left right height

  • op=1 add, op=2 remove
  • left, right: inclusive range (0≤left≤right<n0 \le \text{left} \le \text{right} < n)
  • height: target height

Output

Print the final brick count of each column, one per line from left to right.

Examples6

  1. Example 1

    Input
    10 6
    1 1 8 4
    2 4 9 1
    2 3 6 5
    1 0 5 3
    1 2 2 5
    2 6 7 0
    
    Expected output
    3
    4
    5
    4
    3
    3
    0
    0
    1
    0
    
  2. Example 2

    Input
    5 1
    1 0 4 2
    
    Expected output
    2
    2
    2
    2
    2
    
  3. Example 3

    Input
    3 2
    1 0 2 5
    2 1 1 3
    
    Expected output
    5
    3
    5
    
  4. Example 4

    Input
    10 2
    1 0 9 10
    2 0 9 0
    
    Expected output
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    
  5. Example 5

    Input
    1 2
    1 0 0 7
    1 0 0 3
    
    Expected output
    7
    
  6. Example 6

    Input
    5 3
    1 0 4 1
    1 0 4 3
    2 0 4 2
    
    Expected output
    2
    2
    2
    2
    2