Under construction

Still being built. Things may change

Reporting Documents

Time limit1sMemory limit2048 MB

Summary
Given a binary string with point flips, each query asks for the number of zero positions among x, x+k, x+2k, and so on, up to N.
Level

Medium6 of 10

Topics
Array, Math, Implementation
Solved
No attempts yet

Problem

Each citizen of the ICPC Kingdom must always carry the NN documents issued by the kingdom, numbered from 11 to NN. Guards often ask random citizens for their documents during patrols.

Adrian is a citizen of the ICPC Kingdom and also carries these documents. Through negligence, some of them may be missing. The status of his documents is given by a string BB of length NN, where Bi=1B_i = 1 if document ii is on his hand and Bi=0B_i = 0 if it is missing.

Each of the next QQ days, exactly one of the following happens.

  • 11 xx: Adrian finds his missing document xx, so BxB_x becomes 11. It is guaranteed that Bx=0B_x = 0 right before this event.
  • 22 xx: Adrian loses document xx, so BxB_x becomes 00. It is guaranteed that Bx=1B_x = 1 right before this event.
  • 33 xx kk: A guard asks Adrian for documents x+k⋅ix + k \cdot i for every integer i≥0i \ge 0 such that 1≤x+k⋅i≤N1 \le x + k \cdot i \le N, where x≤kx \le k. Adrian pays a fine of 1 coin for each requested document he cannot provide at that moment.

For each event of type 33, count the total fine Adrian must pay.

Input

The first line contains an integer NN (1≤N≤2000001 \le N \le 200000), the number of documents. The second line contains a string BB of length NN, where the ii-th character is BiB_i (Bi∈{0,1}B_i \in \{0, 1\}), the initial status of document ii.

The third line contains an integer QQ (1≤Q≤2000001 \le Q \le 200000), the number of days. Each of the next QQ lines describes one event and begins with an integer tt (t∈{1,2,3}t \in \{1, 2, 3\}). If t=1t = 1 or t=2t = 2, the line contains one more integer xx (1≤x≤N1 \le x \le N). If t=3t = 3, the line contains two more integers xx and kk (1≤x≤k≤N1 \le x \le k \le N). There is at least one event of type 33.

Output

For each event of type 33, print the number of coins Adrian must pay on its own line.

Examples2

  1. Example 1

    Input
    10
    1010001001
    5
    3 1 2
    2 1
    1 5
    1 9
    3 1 1
    
    Expected output
    2
    5
    
  2. Example 2

    Input
    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
    
    Expected output
    5
    4
    2
    2
    1