This page is still under construction.

Parts of this page are still being built. What you see may change.

Hongik Tourist

Time limit1sMemory limit1024 MB

Summary
Maintain a set of landmark zones on a circle under toggles, clockwise moves, and queries for the distance to the nearest landmark from the current position.
Level

Medium7 of 10

Topics
Segment tree, Binary search, Array, Simulation
Solved
No attempts yet

Problem

Dohyeon becomes a Hongik tourist and wants to tour Hongik University. Hongik University consists of NN zones arranged in a circle. From zone 11 clockwise come zones 22, ..., NN, and going one more step clockwise from zone NN brings you to zone 11.

Hongik University has landmarks. To make his tour worthwhile, Dohyeon wants to visit only landmarks. Dohyeon is standing at zone 11.

Write a program that processes the following queries for Dohyeon.

  • 11 ii : if zone ii is not a landmark, it becomes one; if it is a landmark, its designation is removed. (1≤i≤N1 \leq i \leq N)
  • 22 xx : Dohyeon moves xx steps clockwise. (1≤x≤1091 \leq x \leq 10^9)
  • 33 : print the minimum number of steps Dohyeon must move clockwise to reach a landmark. If no landmark exists, print −1-1.

Input

The first line gives the number of zones NN (1≤N≤500 0001 \leq N \leq 500\,000) and the number of queries QQ (1≤Q≤100 0001 \leq Q \leq 100\,000) as integers.

The second line gives a sequence AA of length NN. If zone ii is a landmark, AiA_i is 11; otherwise it is 00.

From the third line, QQ lines give the queries described above. There is at least one query of type 33.

Output

For each query of type 33, print its value.

Examples1

  1. Example 1

    Input
    5 7
    0 1 0 0 1
    3
    1 2
    3
    2 9
    3
    1 5
    3
    
    Expected output
    1
    4
    0
    -1