atcoder#ABC246H. [ABC246Ex] 01? Queries
[ABC246Ex] 01? Queries
Score : points
Problem Statement
You are given a string of length consisting of 0
, 1
, and ?
.
You are also given queries .
For each , is an integer satisfying and is one of the characters 0
, 1
, and ?
.
For in this order, do the following process for the query .
- First, change the -th character from the beginning of to .
- Then, print the number of non-empty strings, modulo , that can be obtained as a (not necessarily contiguous) subsequence of after replacing each occurrence of
?
in with0
or1
independently.
Constraints
- and are integers.
- is a string of length consisting of
0
,1
, and?
. - is one of the characters
0
,1
, and?
.
Input
Input is given from Standard Input in the following format:
Output
Print lines. For each , the -th line should contain the answer to the -th query (that is, the number of strings modulo at the step 2. in the statement).
3 3
100
2 1
2 ?
3 ?
5
7
10
- The -st query starts by changing to
110
. Five strings can be obtained as a subsequence of110
:0
,1
,10
,11
,110
. Thus, the -st query should be answered by . - The -nd query starts by changing to
1?0
. Two strings can be obtained by the?
in1?0
:100
and110
. Seven strings can be obtained as a subsequence of one of these strings:0
,1
,00
,10
,11
,100
,110
. Thus, the -nd query should be answered by . - The -rd query starts by changing to
1??
. Four strings can be obtained by the?
's in1??
: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 -rd query should be answered by .
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
746884092
532460539
299568633
541985786
217532539
217532539
217532539
573323772
483176957
236273405
Be sure to print the count modulo .