#P4428. [BJOI2018] 二进制
[BJOI2018] 二进制
Description
pupil found that for a decimal number, no matter how its digits are rearranged, it does not affect whether it is a multiple of . He wants to study whether there is a similar property for binary.
So he generated a binary string of length , and hopes that for a subinterval of this binary string, you can find how many position-distinct contiguous substrings satisfy that after rearrangement (leading zeros are allowed), the result is a multiple of .
Two position-distinct subintervals are defined as having different starting positions or different ending positions.
Since he wants to try as many cases as possible, he will sometimes modify one position in the string and will make multiple queries.
Input Format
The first line contains a positive integer , the length of the binary number.
The second line contains space-separated integers, each being or , representing the binary string.
The third line contains an integer , the total number of queries and modifications.
Each of the following lines is either 1 i, meaning pupil toggles the -th position of the string ( becomes or becomes ), or 2 l r, meaning pupil queries the subinterval .
The string is -indexed.
Output Format
For each query, output one line with one integer representing the answer to that query.
4
1 0 1 0
3
2 1 3
1 3
2 3 4
2
3
Hint
Sample Explanation:
- For the first query, the interval contains only the digit , which is a multiple of . The interval can be rearranged into , which is a multiple of . All other intervals cannot be rearranged into a multiple of .
- For the second query, all three intervals can be rearranged into multiples of (note that is also valid).
Constraints:
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号