QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#2978. Binary

Statistics

pupil discovered that for a decimal number, no matter how you rearrange its digits, it does not affect whether it is a multiple of 3. He wants to study whether a similar property exists for binary numbers. He generated a binary string of length $n$ and hopes that for a sub-interval of this binary string, you can calculate how many contiguous substrings with different positions can be rearranged (including leading zeros) to form a multiple of 3. Two sub-intervals are considered different if they have different starting positions or different ending positions. Since he wants to try as many cases as possible, he sometimes modifies a position in the string and performs multiple queries.

Input

The first line contains a positive integer $n$, representing the length of the binary string.

The next line contains $n$ space-separated integers, guaranteed to be either 0 or 1, representing the binary string.

The next line contains an integer $m$, representing the total number of queries and modifications.

Each of the following $m$ lines is either 1 i, indicating that pupil modified the $i$-th position of the string (0 becomes 1 or 1 becomes 0), or 2 l r, indicating that pupil is querying the sub-interval $[l, r]$.

The string is 1-indexed.

Output

For each query, output a single integer on a new line representing the result of the corresponding query.

Examples

Input 1

4
1 0 1 0
3
2 1 3
1 3
2 3 4

Output 1

2
3

Note

For the first query, in the interval $[2, 2]$, there is only the digit 0, which is a multiple of 3. The interval $[1, 3]$ can be rearranged into $011_{(2)} = 3_{(10)}$, which is a multiple of 3. Other intervals cannot be rearranged into a multiple of 3.

For the second query, all three intervals can be rearranged into a multiple of 3 (note that 00 is also valid).

Subtasks

For 20% of the data, $1 \le n, m \le 100$.

For 50% of the data, $1 \le n, m \le 5000$.

For 100% of the data, $1 \le n, m \le 100000$, $l \le r$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.