QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 1024 MB مجموع النقاط: 100

#3746. Never use a tree of trees

الإحصائيات

Bobo is an expert in data structures! He wants to maintain a set $S$ of line segments. Initially, $S$ is empty. He will perform $q$ operations in sequence, where there are $2$ types of operations:

  • Type $1$: Given $l, r$, insert the line segment $[l, r]$ into the set $S$.
  • Type $2$: Given $l, r$, query the number of line segments $[x, y] \in S$ such that $x \leq l \leq r \leq y$.

Help Bobo find the answer for each query.

Input

The input file contains multiple test cases. Process until the end of the file.

The first line of each test case contains $2$ integers $n$ and $q$, where $n$ represents the maximum possible value of $r$ in the operations.

Each of the next $q$ lines contains $3$ integers $t_i, l_i, r_i$, representing that the $i$-th operation is of type $t_i$ with parameters $l_i$ and $r_i$.

Output

For each type $2$ query, output $1$ integer representing the corresponding count.

Examples

Input 1

1 2
1 1 1
2 1 1
4 4
1 1 4
2 2 3
1 1 4
2 2 3

Output 1

1
1
2

Constraints

  • $1 \leq n, q \leq 10^5$
  • $t_i \in \{1, 2\}$
  • $1 \leq l_i \leq r_i \leq n$
  • For operations where $t_i = 2$, the condition $r_i - l_i \leq 2$ holds.
  • The number of test cases does not exceed $10$.

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.