#P12246. 电 van

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

电 van

Problem 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 (1≤x≤n−11 \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

  • 3≤n≤1063 \le n \le 10^6, 1≤m≤1061 \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 n≤3n \le 3 m≤100m \le 100 None
3∼53\sim 5 n≤100n \le 100
6∼96\sim 9 n≤3000n \le 3000 m≤3000m \le 3000
10∼1210\sim 12 n≤106n \le 10^6 m=1m = 1
13∼1613\sim 16 n≤105n \le 10^5 m≤105m \le 10^5 A
17,1817,18 None
19,2019,20 n≤106n \le 10^6 m≤106m \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}.