#P4428. [BJOI2018] 二进制

    ID: 3363 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2018线段树各省省选树状数组北京O2优化构造

[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 33. He wants to study whether there is a similar property for binary.

So he generated a binary string of length nn, 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 33.

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 nn, the length of the binary number.

The second line contains nn space-separated integers, each being 00 or 11, representing the binary string.

The third line contains an integer mm, the total number of queries and modifications.

Each of the following mm lines is either 1 i, meaning pupil toggles the ii-th position of the string (00 becomes 11 or 11 becomes 00), or 2 l r, meaning pupil queries the subinterval [l,r][l,r].

The string is 11-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 [2,2][2,2] contains only the digit 00, which is a multiple of 33. The interval [1,3][1,3] can be rearranged into 011(2)=3(10)011_{(2)} = 3_{(10)}, which is a multiple of 33. All other intervals cannot be rearranged into a multiple of 33.
  • For the second query, all three intervals can be rearranged into multiples of 33 (note that 0000 is also valid).

Constraints:

  • For 20%20\% of the testdata, 1n,m1001 \leq n,m \leq 100.
  • For 50%50\% of the testdata, 1n,m50001 \leq n,m \leq 5000.
  • For 100%100\% of the testdata, 1n,m1000001 \leq n,m \leq 100000, lrl \leq r.

Translated by ChatGPT 5