#P12246. van City Subsequence Swap

    ID: 14352 Type: Default 1000ms 256MiB

van City Subsequence Swap

van City Subsequence Swap

Little O loves to visit van city and is fascinated by the string van. He has prepared a string problem related to van.

You are given a string s of length \( n \) consisting only of the characters v, a, and n. Let \( s_i \) denote the \( i\)-th character in \( s \).

Then, you will be given \( m \) operations. In each operation, you are given an integer \( x \) (\(1 \le x \le n-1\)), meaning that you need to swap \( s_x \) and \( s_{x+1} \).

After each swap operation, output the number of times the string \( \texttt{van} \) occurs as a subsequence in the current string.

A string \( t \) is a subsequence of \( s \) if and only if \( t \) can be obtained by deleting zero or more characters from \( s \) without changing the order of the remaining characters.

The subsequence count should be computed using the formula: \[ \text{For each character in } s:\\ \begin{cases} \text{if } s_i = \texttt{v}: & count_v++ \\ \text{if } s_i = \texttt{a}: & count_{va} += count_v \\ \text{if } s_i = \texttt{n}: & count_{van} += count_{va} \end{cases} \]

inputFormat

The first line contains two integers \( n \) and \( m \) separated by a space.

The second line contains a string \( s \) of length \( n \) consisting only of the characters v, a, and n.

The following \( m \) lines each contain an integer \( x \) (\(1 \le x \le n-1\)) representing the position where a swap between \( s_x \) and \( s_{x+1} \) should occur.

outputFormat

After each swap, output a single line containing the number of times the subsequence van appears in the current string.

sample

3 1
van
1
1

</p>