Reporting Documents

시간 제한1초메모리 제한2048 MB

요약
이진 배열에서 한 원소씩 갱신하는 연산과, 각 질의 (x, k)마다 x, x+k, x+2k, ... 처럼 등차수열을 이루는 위치 중 값이 0인 개수를 세는 문제이다.
난이도

보통10점 중 7점

유형
배열, 수학, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

Each citizen in ICPC Kingdom must have their NN kingdom-issued documents, numbered from 11 to NN, 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 BB where B_iB\_i represents the existence of document ii. If document $$i is on his hand, then B_i=1B\_i = 1. Otherwise, B_i=0B\_i = 0 if document ii is missing.

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

  • 11 xx. Adrian found his missing document xx, so B_xB\_x is updated to 11 (it is guaranteed that B_x=0B\_x = 0 right before this scenario).
  • 22 xx. Adrian lost his document xx, so B_xB\_x is updated to 00 (it is guaranteed that B_x=1B\_x = 1 right before this scenario).
  • 33 xx kk. A guard asks Adrian for document x+k⋅ix + k \cdot i, where x≤kx ≤ k, for all ii that satisfies 0≤i0 ≤ i and 1≤x+k⋅i≤N1 ≤ x + k \cdot i ≤ N. For each document he couldn’t provide when the guard asked for it, Adrian will be fined for 11 coin.

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

입력

Input begins with an integer NN (1≤N≤200,0001 ≤ N ≤ 200\\, 000) representing the number of documents. The next line contains a string BB of length NN, where the iith character of BB is B_iB\_i (B_i∈0,1B\_i \in \\{ 0, 1\\}), the initial existence status of document ii.

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

출력

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

예제2

  1. 예제 1

    입력
    10
    1010001001
    5
    3 1 2
    2 1
    1 5
    1 9
    3 1 1
    
    예상 출력
    2
    5
    
  2. 예제 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
    
    예상 출력
    5
    4
    2
    2
    1