#abc246h. Ex - 01? Queries

Ex - 01? Queries

Score : 600600 points

问题描述

给定一个长度为 NN 的字符串 SS,其中包含字符 01?

同时,你也将获得 QQ 组查询 (x1,c1)(x_1, c_1), (x2,c2)(x_2, c_2), \ldots, (xQ,cQ)(x_Q, c_Q)
对于每组查询,其中 i=1,2,,Qi = 1, 2, \ldots, Q,满足整数 xix_i 满足 1xiN1 \leq x_i \leq N,而 cic_i 是字符 01? 中的一个。

按照 i=1,2,,Qi = 1, 2, \ldots, Q 的顺序,对查询 (xi,ci)(x_i, c_i) 执行以下过程:

  1. 首先,将字符串 SS 开头的第 xix_i 个字符更改为 cic_i
  2. 然后,计算在将 SS 中出现的所有 ? 独立替换为 01 后,可以获得的非空子序列(不一定是连续子串)的数量,并对 998244353998244353 取模后输出这个数量。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a string SS of length NN consisting of 0, 1, and ?.

You are also given QQ queries (x1,c1),(x2,c2),,(xQ,cQ)(x_1, c_1), (x_2, c_2), \ldots, (x_Q, c_Q).
For each i=1,2,,Qi = 1, 2, \ldots, Q, xix_i is an integer satisfying 1xiN1 \leq x_i \leq N and cic_i is one of the characters 0 , 1, and ?.

For i=1,2,,Qi = 1, 2, \ldots, Q in this order, do the following process for the query (xi,ci)(x_i, c_i).

  1. First, change the xix_i-th character from the beginning of SS to cic_i.
  2. Then, print the number of non-empty strings, modulo 998244353998244353, that can be obtained as a (not necessarily contiguous) subsequence of SS after replacing each occurrence of ? in SS with 0 or 1 independently.

Constraints

  • 1N,Q1051 \leq N, Q \leq 10^5
  • NN and QQ are integers.
  • SS is a string of length NN consisting of 0, 1, and ?.
  • 1xiN1 \leq x_i \leq N
  • cic_i is one of the characters 0 , 1, and ?.

Input

Input is given from Standard Input in the following format:

NN QQ

SS

x1x_1 c1c_1

x2x_2 c2c_2

\vdots

xQx_Q cQc_Q

Output

Print QQ lines. For each i=1,2,,Qi = 1, 2, \ldots, Q, the ii-th line should contain the answer to the ii-th query (xi,ci)(x_i, c_i) (that is, the number of strings modulo 998244353998244353 at the step 2. in the statement).

Sample Input 1

3 3
100
2 1
2 ?
3 ?

Sample Output 1

5
7
10
  • The 11-st query starts by changing SS to 110. Five strings can be obtained as a subsequence of S=S = 110: 0, 1, 10, 11, 110. Thus, the 11-st query should be answered by 55.

  • The 22-nd query starts by changing SS to 1?0. Two strings can be obtained by the ? in S=S = 1?0: 100 and 110. Seven strings can be obtained as a subsequence of one of these strings: 0, 1, 00, 10, 11, 100, 110. Thus, the 22-nd query should be answered by 77.

  • The 33-rd query starts by changing SS to 1??. Four strings can be obtained by the ?'s in S=S = 1??: 100, 101, 110, 111. Ten strings can be obtained as a subsequence of one of these strings: 0, 1, 00, 01, 10, 11, 100, 101, 110, 111. Thus, the 33-rd query should be answered by 1010.

Sample Input 2

40 10
011?0??001??10?0??0?0?1?11?1?00?11??0?01
5 0
2 ?
30 ?
7 1
11 1
3 1
25 1
40 0
12 1
18 1

Sample Output 2

746884092
532460539
299568633
541985786
217532539
217532539
217532539
573323772
483176957
236273405

Be sure to print the count modulo 998244353998244353.

update @ 2024/3/10 10:34:46