#P4344. [SHOI2015] 脑洞治疗仪

[SHOI2015] 脑洞治疗仪

Description

The inventor SHTSC, who once created the automatic problem-solving machine, has unveiled his new invention: the Brainhole Treatment Device — a mysterious apparatus that can treat the ever-enlarging “brainholes” caused by his inventions.

For simplicity, we regard the brain as a 01 sequence. 11 means the tissue at that position is working normally, and 00 means it is a brainhole.

1      0      1      0      0      0      1      1      1      0

The basic principle for repairing a certain brainhole is to excavate another contiguous region and use the normal tissue from it to fill the hole. (So is the brainhole treatment device actually a treatment device for brainholes?)

For example, if we use positions 88 to 1010 to repair the hole from positions 11 to 44, we get:

1      1      1      1      0      0      1      0      0      0

If we then use positions 11 to 44 to repair positions 88 to 1010:

0      0      0      0      0      0      1      1      1      1

This is because the Brainhole Treatment Device discards any excess tissue.

If we then use positions 77 to 1010 to fill positions 11 to 66:

1      1      1      1      0      0      0      0      0      0

This is because if the excavated normal tissue is not enough, the device only fills the brainhole as much as possible starting from the earlier positions (smaller indices).

Assume that initially SHTSC has no brainholes. Given a sequence of digging and treatment operations, you need to answer online: within a given interval of the brain, what is the size of the largest contiguous brainhole.

Input Format

The first line contains two integers n,mn, m, meaning SHTSC’s brain is divided into nn contiguous regions numbered from 11 to nn, and there are mm operations.

Each of the following mm lines is in one of the following three formats:

  • 0lr0\quad l\quad r: SHTSC digs a brainhole covering the range [l,r][l, r].
  • 1l0r0l1r11\quad l_0\quad r_0\quad l_1\quad r_1: SHTSC performs one treatment, using the normal tissue from l0l_0 to r0r_0 to repair the brainholes from l1l_1 to r1r_1.
  • 2lr2\quad l\quad r: SHTSC asks for the size of the largest brainhole within the interval [l,r][l, r].

All the above intervals lie within [1,n][1, n].

Output Format

For each query, output one line with one integer, the size of the largest contiguous brainhole within the query interval.

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
3
3
6
6

Hint

For 20%20\% of the testdata, n,m100n, m \leq 100. For 50%50\% of the testdata, n,m20000n, m \leq 20000. For 100%100\% of the testdata, n,m200000n, m \leq 200000.

Translated by ChatGPT 5