#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 aa of length nn.

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 ll and rr, find the maximum length of a “Shino sequence” in aa whose both endpoints are within [l,r][l,r].

This problem stumped Abbi. Abbi decided to cross-dress. When Abbi cross-dresses, the sequence undergoes a magical change: it can choose a position pp that it likes within the query interval [l,r][l,r], and separately reverse the intervals [l,p][l,p] and (p,r](p,r].

Abbi wants to know: after cross-dressing at most kk times (you may choose to do fewer than kk 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 nn and mm, representing the sequence length and the number of operations.

The second line contains nn numbers, where the ii-th number is the initial value aia_i.

The next mm lines each describe an operation in the following format:

  1. RR ll rr xx: set all numbers in the interval [l,r][l,r] to xx.
  2. QQ ll rr kk: query the maximum length of a “Shino sequence” that can be obtained by cross-dressing at most kk times within [l,r][l,r].

Note: Queries are independent. That is, after each query, the sequence is restored; the reversal operations are not actually applied.

Output Format

For each QQ 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 20%20\% of the testdata, 1n,m1001 \le n,m \le 100.
  • For another 10%10\% of the testdata, all queries have k=0k=0.
  • For another 10%10\% of the testdata, there are no RR operations.
  • For 100%100\% of the testdata, 1n,m2000001 \le n,m \le 200000, 0k10000 \le k \le 1000, 1ai,x1091 \le a_i,x \le 10^9, 1lrn1 \le l \le r \le n.

Special restriction: for the last 80%80\% 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 [1,4][1,4] and [5,6][5,6] separately, obtaining:

3 3 3 3 3 2

At this time, the longest “Shino sequence” has length 55. 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