#P12246. 电 van

    ID: 11688 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>洛谷原创O2优化前缀和洛谷月赛

电 van

Description

You are given a string ss of length nn consisting of characters v\texttt{v}, a\texttt{a}, and n\texttt{n}. Let sis_i denote the ii-th character of ss.

Little O will perform mm operations. In each operation, you are given an integer xx (1xn11 \le x \le n-1), requiring you to swap sxs_x and sx+1s_{x+1}.

After each operation, output the number of times van\texttt{van} appears as a subsequence in the modified string.

  • A string tt is a subsequence of ss if it can be obtained by deleting zero or more characters from ss without changing the order of the remaining characters.

Input Format

The input consists of m+2m+2 lines:

  • Line 11: Two integers nn and mm, the string length and number of operations.
  • Line 22: A string ss of length nn.
  • Lines 33 to m+2m+2: Each line contains an integer xix_i, representing the ii-th operation.

Output Format

Output mm lines, where the ii-th line contains the answer after the ii-th operation.

8 3
vvvaannn
4
3
5
18
15
12

Hint

Sample #1 Explanation

Initial State: s=vvvaannns = \texttt{vvvaannn}

  • After swapping positions 44 and 55: ss remains unchanged. van\texttt{van} appears 18 times.
  • After swapping positions 33 and 44: s=vvavannns = \texttt{vvavannn}. van\texttt{van} appears 15 times.
  • After swapping positions 55 and 66: s=vvavnanns = \texttt{vvavnann}. van\texttt{van} appears 12 times.

Constraints

  • 3n1063 \le n \le 10^6, 1m1061 \le m \le 10^6
  • si{v,a,n}s_i \in \{\texttt{v}, \texttt{a}, \texttt{n}\}

Subtask Details

Test Case nn Range mm Range Special Property
1,21,2 n3n \le 3 m100m \le 100 None
353\sim 5 n100n \le 100
696\sim 9 n3000n \le 3000 m3000m \le 3000
101210\sim 12 n106n \le 10^6 m=1m = 1
131613\sim 16 n105n \le 10^5 m105m \le 10^5 A
17,1817,18 None
19,2019,20 n106n \le 10^6 m106m \le 10^6

Special Property A: In all swap operations, at least one of sxs_x or sx+1s_{x+1} is a\texttt{a}.