QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#4894. Senior Sister Buys Melons

Statistics

There is a melon stall with $m$ melons, numbered from $1$ to $m$. There are $n$ events occurring in sequence, each being one of the following two types:

  • 1 l r where $1\leqslant l \leqslant r \leqslant m$: A student arrives wanting to purchase all melons with indices in the range $[l, r]$. To satisfy this student, all melons in $[l, r]$ must be provided.
  • 2 l r where $1\leqslant l \leqslant r \leqslant m$: The students make an inquiry to the stall owner. Following the principle that "one melon can be sold to at most one student," and considering only melons with indices in $[l, r]$, inquire about the maximum number of student requests that can be satisfied. Since the students are just being difficult, they are only inquiring and will not actually purchase the melons; the inquiries are independent of each other.

If the stall owner answers incorrectly or cannot answer, the students will think the owner is hiding something, and the consequences will be severe!

As a friend of the stall owner, Liu Huaqiang, please help him.

Brief Problem Statement: There are $n$ operations, each being one of the following:

  • 1 l r: Add the interval $[l, r]$, where $1\leqslant l \leqslant r \leqslant m$.
  • 2 l r: Query the interval $[l, r]$, where $1\leqslant l \leqslant r \leqslant m$, to find the maximum number of disjoint intervals that are contained within $[l, r]$.

We say an interval $[l_1, r_1]$ is contained within $[l_2, r_2]$ if and only if $l_2\leqslant l_1 \leqslant r_1 \leqslant r_2$.

Input

The first line contains two integers $n$ and $m$.

The next $n$ lines each contain three integers $opt, l, r$.

Output

For each type 2 operation, output a single integer on a new line.

Examples

Input 1

16 16
2 3 4
1 3 7
2 1 3
2 1 16
1 1 5
1 9 10
2 5 16
1 2 6
2 5 13
1 11 12
2 7 11
2 4 9
1 13 14
1 15 16
1 4 8
2 4 13

Output 1

0
0
1
1
1
1
0
3

Input 2

16 16
1 2 4
2 3 10
1 13 15
1 7 9
1 3 5
2 1 16
2 3 8
2 1 13
1 8 10
2 8 8
2 6 9
2 6 16
1 5 7
2 3 3
1 8 10
2 8 8

Output 2

0
3
1
2
0
1
2
0
0

Constraints

For $20\%$ of the data, $n, m \leqslant 2 \times 10^3$.

For $50\%$ of the data, $n, m \leqslant 8 \times 10^4$.

For $100\%$ of the data, $n, m \leqslant 3 \times 10^5$, $1\leqslant opt \leqslant 2$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.