#P7809. [JRKSJ R2] 01 序列

    ID: 6374 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2021洛谷原创O2优化st表,稀疏表

[JRKSJ R2] 01 序列

Description

You are given a 0101 sequence a1na_{1\sim n} of length nn. Then there are mm queries of two types:

  • 1 l r: query the length of the longest non-decreasing subsequence in the interval from ll to rr.
  • 2 l r: query the length of the longest increasing subsequence in the interval from ll to rr.

Input Format

The input contains m+2m+2 lines.
Line 11 contains two positive integers n,mn, m.
Line 22 contains nn numbers 00 or 11, representing the sequence a1na_{1\sim n}.
The next mm lines each contain three positive integers describing one query, in the format above.

Output Format

Output mm lines.
For each query, compute the answer and output it.

8 4
0 1 1 0 1 0 0 1
1 1 8
2 1 8
1 3 6
2 5 6
5
2
2
1

Hint

This problem uses bundled testdata.

Subtask\text{Subtask} nn\le mm\le Special Property Score
1\text{1} 10610^6 All aia_i are equal 55
2\text{2} 10310^3 None 1010
3\text{3} 10410^4 1515
4\text{4} 10510^5 3030
5\text{5} 10610^6 5×1065\times10^6 4040
6\text{6} hack testdata 00

For 100%100\% of the testdata, 1n1061\le n\le 10^6, 1m5×1061\le m\le 5\times10^6, and 0ai10\le a_i\le 1.

The input and output size is extremely large, so please use fast I/O methods.

Sample Explanation:

For the first query, valid sequences include {0,1,1,1,1}\{0,1,1,1,1\} and {0,0,0,0,1}\{0,0,0,0,1\}.
For the second query, valid sequences include {0,1}\{0,1\}.
For the third query, valid sequences include {0,0}\{0,0\}, {0,1}\{0,1\}, and {1,1}\{1,1\}.
For the fourth query, valid sequences include {0}\{0\} and {1}\{1\}.

Upd 2021.8.16\text{Upd 2021.8.16}: Added two sets of hack testdata.

Translated by ChatGPT 5