Problem10280--CF EDU - Segment Tree P1 - Step 4 - E. Earthquakes

10280: CF EDU - Segment Tree P1 - Step 4 - E. Earthquakes

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 MiB

Description

A city is a sequence of $n$ cells numbered from $0$ to $n−1$. Initially, all cells are empty. Then $m$ events of one of two types occur sequentially:
  • a building with the strength $h$ is being constructed in the cell $i$ (if the building already existed in this cell, it is demolished and replaced with a new one),
  • in the interval from $l$ to $r−1$ an earthquake of power $p$ happens, it destroys all buildings whose strength is not more than $p$. Your task is for each earthquake to say how many buildings it will destroy.

Input

The first line contains the numbers $n,m$, the number of cells and the number of events $(1≤n,m≤10^5)$. 
The following $m$ lines describe events. The description of each event is as follows:
  • 1 i h: a building with the strength $h$ is constructed in the cell $i\ (0≤i<n,\ 1≤h≤10^9)$.
  • 2 l r p: an earthquake of power $p$ happens on a segment from $l$ to $r−1\ (0≤l<r≤n,\ 0≤p≤10^9)$.

Output

For each event of the second type, print how many buildings were destroyed.

Sample 1 Input

5 9
1 0 3
1 2 5
2 0 4 3
1 1 4
1 2 7
2 1 3 6
1 3 8
1 4 4
2 0 5 10

Sample 1 Output

1
1
3

HINT

CF EDU.

Source/Category