#P5500. [LnOI2019] 真正的 OIer 从不女装
[LnOI2019] 真正的 OIer 从不女装
Background
Problem provider: Asada Shino.
As everyone knows, there are only zero times and countless times for cross-dressing.
Problem Description
Given a sequence of length .
There is the following definition: if all numbers in a sequence are the same, then this sequence is called a “Shino sequence”.
For each query, given and , find the maximum length of a “Shino sequence” in whose both endpoints are within .
This problem stumped Abbi. Abbi decided to cross-dress. When Abbi cross-dresses, the sequence undergoes a magical change: it can choose a position that it likes within the query interval , and separately reverse the intervals and .
Abbi wants to know: after cross-dressing at most times (you may choose to do fewer than times, or not cross-dress at all), what is the maximum possible length of a “Shino sequence” that can be obtained?
Input Format
The first line contains and , representing the sequence length and the number of operations.
The second line contains numbers, where the -th number is the initial value .
The next lines each describe an operation in the following format:
- : set all numbers in the interval to .
- : query the maximum length of a “Shino sequence” that can be obtained by cross-dressing at most times within .
Note: Queries are independent. That is, after each query, the sequence is restored; the reversal operations are not actually applied.
Output Format
For each operation, output the answer to the query.
10 4
3 3 3 3 2 3 3 3 2 2
Q 1 6 1
Q 1 6 0
R 8 8 2
Q 5 10 1
5
4
4
Hint
Time and memory limits: 1s / 512MB.
Constraints:
- For of the testdata, .
- For another of the testdata, all queries have .
- For another of the testdata, there are no operations.
- For of the testdata, , , , .
Special restriction: for the last of the testdata, it is guaranteed that ODT can be hacked.
Sample explanation:
For the first query, the queried interval is:
3 3 3 3 2 3
Cross-dress once, and reverse and separately, obtaining:
3 3 3 3 3 2
At this time, the longest “Shino sequence” has length . It can be proven that no other way of cross-dressing can produce a longer “Shino sequence”.
Subsequent queries proceed similarly.
It is recommended to use fast input.
Translated by ChatGPT 5