#P6492. Longest Valid Substring after Toggle Operations
Longest Valid Substring after Toggle Operations
Longest Valid Substring after Toggle Operations
You are given a sequence \( a \) of length \( n \), where initially every element is the character L
. There are \( q \) operations. In each operation, you are given an index \( x \) (1-indexed). If \( a_x = L \), change it to R
, otherwise change it to L
(i.e. toggle it).
A string \( s \), consisting only of the characters L
and R
, is said to satisfy the condition if it does not contain two consecutive characters that are different. Equivalently, every two adjacent characters in \( s \) must be identical.
After each operation, output the length of the longest contiguous substring (subarray) of \( a \) that satisfies the condition.
Note: The positions are 1-indexed.
inputFormat
The first line contains two integers \( n \) and \( q \) — the length of the sequence and the number of operations.
The next \( q \) lines each contain an integer \( x \) (1-indexed) indicating the position to toggle.
outputFormat
After each operation, output one integer — the length of the longest contiguous substring that satisfies the condition.
sample
5 3
3
1
5
2
2
1
</p>