시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB32266.667%

문제

Each citizen in ICPC Kingdom must have their $N$ kingdom-issued documents, numbered from $1$ to $N$, on their hands at any time. The guards often ask random citizens for their documents during their patrol.

As a citizen of ICPC Kingdom, Adrian also has these documents on his hands as well; however, some of them might be missing due to his negligence. The existence status of all of his documents are represented by a string $B$ where $B_i$ represents the existence of document $i$. If document $$i is on his hand, then $B_i = 1$. Otherwise, $B_i = 0$ if document $i$ is missing.

For each of the next $Q$ days, exactly one of the following scenarios will happen.

  • $1$ $x$. Adrian found his missing document $x$, so $B_x$ is updated to $1$ (it is guaranteed that $B_x = 0$ right before this scenario).
  • $2$ $x$. Adrian lost his document $x$, so $B_x$ is updated to $0$ (it is guaranteed that $B_x = 1$ right before this scenario).
  • $3$ $x$ $k$. A guard asks Adrian for document $x + k \cdot i$, where $x ≤ k$, for all $i$ that satisfies $0 ≤ i$ and $1 ≤ x + k \cdot i ≤ N$. For each document he couldn’t provide when the guard asked for it, Adrian will be fined for $1$ coin.

For each scenarios involving a guard (i.e. scenario $3$), Adrian asks you to count how many coins he needs to pay for the fine.

입력

Input begins with an integer $N$ ($1 ≤ N ≤ 200\, 000$) representing the number of documents. The next line contains a string $B$ of length $N$, where the $i$th character of $B$ is $B_i$ ($B_i \in \{ 0, 1\}$), the initial existence status of document $i$.

The next line contains an integer $Q$ ($1 ≤ Q ≤ 200\, 000$) representing the number of days. Each of the next $Q$ lines contains a scenario. Each scenario begins with an integer $t$ ($t \in \{1, 2, 3\}$). If $t = 1$ or $t = 2$, then it is followed by an integer $x$ ($1 ≤ x ≤ N$) representing scenario $1$ or $2$, respectively. It is guaranteed that integer $x$ in scenarios $1$ and $2$ satisfy the scenario description. If $t = 3$, then it is followed by two integers $x$ $k$ ($1 ≤ x ≤ k ≤ N$) representing scenario $3$. There will be at least one scenario of type $3$.

출력

For each scenario $3$, output an integer in a single line representing how many coins Adrian needs to pay for the fine for that day.

예제 입력 1

10
1010001001
5
3 1 2
2 1
1 5
1 9
3 1 1

예제 출력 1

2
5

At first, Adrian only has documents $1$, $3$, $7$, and $10$ on his hand.

On day $1$, a guard asks Adrian for documents $1 + 2 \cdot i$, i.e. documents $1$, $3$, $5$, $7$, and $9$. Adrian doesn’t have documents $5$ and $9$ on his hand, thus, he will be fined for $2$ coins.

On day $2$, $3$, and $4$, he lost document $1$, found document $5$, and found document $9$, respectively.

On day $5$, a guard asks Adrian for documents $1 + 1 \cdot i$, i.e. all documents from $1$ to $10$. Adrian doesn’t have documents $1$, $2$, $4$, $6$, and $8$ on his hand, thus, he will be fined for $5$ coins.

예제 입력 2

25
0010000010100110100000101
10
3 2 4
1 5
1 21
2 11
2 5
3 1 5
1 5
3 5 5
3 3 8
3 1 25

예제 출력 2

5
4
2
2
1