QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 256 MB Puntuación total: 100

#15594. Brain-Hole Therapy Device

Estadísticas

The inventor SHTSC, who once invented an automatic problem-solving machine, has unveiled his new invention: the Brainhole Therapy Device—a mysterious apparatus that can treat the "brainholes" that have been growing due to his inventions.

For simplicity, we represent the brain as a $01$ sequence. $1$ represents that the brain tissue at this position is working normally, and $0$ represents a brainhole.

$$1 \quad 0 \quad 1 \quad 0 \quad 0 \quad 0 \quad 1 \quad 1 \quad 1 \quad 0$$

The basic principle of the Brainhole Therapy Device is to excavate a continuous region of normal brain tissue and use it to fill in a brainhole.

For example, using the brain tissue from position $8$ to position $10$ to repair the brainhole from position $1$ to position $4$, we get:

$$1 \quad 1 \quad 1 \quad 1 \quad 0 \quad 0 \quad 1 \quad 0 \quad 0 \quad 0$$

If we then use the brain tissue from position $1$ to position $4$ to repair the brainhole from position $8$ to position $10$:

$$0 \quad 0 \quad 0 \quad 0 \quad 0 \quad 0 \quad 1 \quad 1 \quad 1 \quad 1$$

This is because the Brainhole Therapy Device simply discards any excess brain tissue.

If we then use the brain tissue from position $7$ to position $10$ to fill the brainhole from position $1$ to position $6$:

$$1 \quad 1 \quad 1 \quad 1 \quad 0 \quad 0 \quad 0 \quad 0 \quad 0 \quad 0$$

This is because if the newly excavated brain tissue is insufficient, the Brainhole Therapy Device will only fill the brainholes starting from the earliest positions. Assume that initially, SHTSC has no brainholes. Given a sequence of operations involving digging brainholes and performing brainhole therapy, you need to answer SHTSC's questions in real-time: what is the size of the largest continuous brainhole region in a given interval of the brain?

Input

The first line contains two integers $n$ and $m$, representing that SHTSC's brain can be divided into $n$ continuous regions numbered from $1$ to $n$. There are $m$ operations.

Each of the following $m$ lines is in one of the following three formats:

  • $0 \ l \ r$: SHTSC digs a brainhole from $l$ to $r$.
  • $1 \ l_0 \ r_0 \ l_1 \ r_1$: SHTSC performs a brainhole therapy, using the brain tissue from $l_0$ to $r_0$ to repair the brainhole from $l_1$ to $r_1$.
  • $2 \ l \ r$: SHTSC asks for the size of the largest brainhole in the interval from $l$ to $r$.

Output

For each query, output one integer per line, representing the size of the largest continuous brainhole region in the queried interval.

Examples

Input 1

10 10
0 2 2
0 4 6
0 10 10
2 1 10
1 8 10 1 4
2 1 10
1 1 4 8 10
2 1 10
1 7 10 1 6
2 1 10

Output 1

3
3
6
6

Input 2

10 8
0 1 2
2 3 4
2 1 2
0 4 5
0 10 10
2 1 5
1 1 5 10 10
2 1 5

Output 2

0
2
2
5

Note

Explanation for Example 1: $2 \ 1 \ 10 \ / \ \text{ans} = 3$ $1 \ 0 \ 1 \ 0 \ 0 \ 0 \ 1 \ 1 \ 1 \ 0$ $2 \ 1 \ 10 \ / \ \text{ans} = 3$ $1 \ 1 \ 1 \ 1 \ 0 \ 0 \ 1 \ 0 \ 0 \ 0$ $2 \ 1 \ 10 \ / \ \text{ans} = 6$ $0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 1 \ 1 \ 1 \ 1$ $2 \ 1 \ 10 \ / \ \text{ans} = 6$ $1 \ 1 \ 1 \ 1 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0$

Explanation for Example 2: $2 \ 3 \ 4 \ / \ \text{ans} = 0$ $0 \ 0 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1$ $2 \ 1 \ 2 \ / \ \text{ans} = 2$ $0 \ 0 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1$ $2 \ 1 \ 5 \ / \ \text{ans} = 2$ $0 \ 0 \ 1 \ 0 \ 0 \ 1 \ 1 \ 1 \ 1 \ 0$ $2 \ 1 \ 5 \ / \ \text{ans} = 5$ $0 \ 0 \ 0 \ 0 \ 0 \ 1 \ 1 \ 1 \ 1 \ 1$

Constraints

  • For 20% of the data: $n, m \le 100$.
  • For 50% of the data: $n, m \le 20000$. The number of query operations does not exceed $100$.
  • For 100% of the data: $n, m \le 200000$, $1 \le l \le r \le n$.

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.