#P5640. 【CSGRound2】逐梦者的初心

    ID: 4586 远端评测题 250ms 500MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dpO2优化状态压缩,状压位运算,按位洛谷月赛

【CSGRound2】逐梦者的初心

Description

You are given a string SS of length nn.

There are mm operations, and it is guaranteed that mnm \le n.

You also have a string TT, which is empty at the beginning.

There are two types of operations.

The first type of operation:

Append one character to the end of string TT.

The second type of operation:

Prepend one character to the beginning of string TT.

After each operation, you need to output how many l[1,T.size]l \in [1,T.size] satisfy the following condition:

For i[1,l]\forall i \in [1,l], we have TT.sizel+iSiT_{T.size-l+i} \ne S_{i}.

Tip:Tip: String indices start from 1. T.sizeT.size denotes the length of TT.

Input Format

The first line contains two positive integers n,mn,m.

The second line contains nn positive integers separated by spaces. The ii-th integer represents SiS_i.

Next, there are mm lines, each containing two numbers opt,chopt,ch. opt=0opt=0 means appending a character chch to the end of TT, and opt=1opt=1 means prepending a character chch to the beginning of TT.

Output Format

Output mm lines. Each line contains one non-negative integer representing the answer after the mm-th operation.

10 3
1 2 3 1 2 3 2 3 2 3
0 1
1 2
0 3
0
1
1

Hint

Note: This problem uses bundled tests. You can get the score of a subtask only after you pass all test points of that subtask.

For all testdata, $n \leq 10^6,m \leq 3.3333 \times 10^4,|\sum|\leq10^3,S_i \in [1,|\sum|]$. (\sum denotes the alphabet)

subtask 1 (17%)(17\%): m333m \leq 333.

subtask 2 (33%)(33\%): m3333m \leq 3333.

subtask 3 (20%)(20\%): 2|\sum|\leq2.

subtask 4 (30%)(30\%): no special constraints.

Sample Explanation:

After the first operation, T="1"T="1".

When l=1l=1, T[1]=S[1]T[1]=S[1], so the answer is 0.

After the second operation, T="21"T="21".

When l=1l=1, T[2]=S[1]T[2]=S[1].

When l=2l=2, T[1]!=S[1]T[1]!=S[1], T[2]!=S[2]T[2]!=S[2], so the answer is 1.

After the third operation, T="213"T="213".

When l=1l=1, T[3]!=S[1]T[3]!=S[1].

When l=2l=2, T[2]=S[1]T[2]=S[1].

When l=3l=3, T[3]=S[3]T[3]=S[3], so the answer is 1.

Translated by ChatGPT 5