#P8473. Coloring on a Number Line

    ID: 21648 Type: Default 1000ms 256MiB

Coloring on a Number Line

Coloring on a Number Line

We are given (n) special integer points on the positive number line with positions (p_1, p_2, \dots, p_n) (given in increasing order) and an initial black/white coloring for each point. We maintain an initially empty multiset (S) of segments. Then there are (q) operations. Each operation is one of the following:

  1. Add Operation:

    An operation of the form

    [ 1\ l\ r ]

    adds all segments ([x,y]) satisfying (l \le x \le y \le r) with the restriction that both endpoints (x) and (y) must be among the special points (i.e. (x,y\in{p_1,\dots,p_n})). In other words, if the special points within ([l,r]) are (p_L,p_{L+1},\dots,p_R), this operation adds every segment ([p_i,p_j]) for (L \le i \le j \le R).

  2. Remove Operation:

    An operation of the form

    [ 2\ x ]

    removes (withdraws) all the segments that were added by the (x\text{-th}) operation (which is guaranteed to be an add operation).

After the initial state and after each operation, we perform the following hypothetical (i.e. independent for each state) coloring procedure any number of times (possibly zero):

Select a segment ([x,y]) from (S) such that the two special points at positions (x) and (y) are black; then, color all special points between (x) and (y) (inclusive) black.

Determine whether there exists at least one legal sequence of such coloring moves so that eventually every special point (all (p_i)) on the positive axis becomes black.

(\textbf{Note}): All queries (initial state and after each operation) are independent hypothetical scenarios; that is, the coloring procedure in one scenario does not affect the next.

inputFormat

The input begins with two integers \(n\) and \(q\) \( (1 \le n, q \le \text{some limit})\). The second line contains \(n\) integers \(p_1, p_2, \dots, p_n\) in strictly increasing order.

The third line is a string of length \(n\) consisting of characters 'B' (black) or 'W' (white) representing the initial color of each special point.

Each of the following \(q\) lines contains an operation in one of the following formats:

  • 1 l r — add all segments whose endpoints (both special points) lie in the interval \([l, r]\).
  • 2 x — remove all segments added by the \(x\text{-th}\) add operation.

After the initial state and after each operation, you should determine whether it is possible to eventually turn all special points black using the allowed coloring moves.

outputFormat

Output \(q+1\) lines. The first line corresponds to the initial state (with \(S\) empty) and each subsequent line corresponds to the state after each operation. For each state, output YES if it is possible to eventually color every special point black, or NO otherwise.

Explanation of the Coloring Procedure:
A coloring move can be performed on any segment \([p_i, p_j]\) from the current multiset \(S\) provided that both endpoints \(p_i\) and \(p_j\) are already black. Doing so will color every special point between these two endpoints black as well. Notice that segments in \(S\) come in groups: each add operation inserts all segments among a contiguous block of special points. As a consequence, within such a block, if at least two points are black initially, you can eventually color the entire block black. However, any special point that is not covered by any segment in \(S\) (or is isolated in \(S\)) must be black from the beginning.

sample

5 2
1 3 5 7 9
BWBWB
1 1 5
1 5 9
NO

NO YES

</p>