Hongik Tourist
Time limit1sMemory limit1024 MB
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 zones arranged in a circle. From zone clockwise come zones , ..., , and going one more step clockwise from zone brings you to zone .
Hongik University has landmarks. To make his tour worthwhile, Dohyeon wants to visit only landmarks. Dohyeon is standing at zone .
Write a program that processes the following queries for Dohyeon.
- : if zone is not a landmark, it becomes one; if it is a landmark, its designation is removed. ()
- : Dohyeon moves steps clockwise. ()
- : print the minimum number of steps Dohyeon must move clockwise to reach a landmark. If no landmark exists, print .
Input
The first line gives the number of zones () and the number of queries () as integers.
The second line gives a sequence of length . If zone is a landmark, is ; otherwise it is .
From the third line, lines give the queries described above. There is at least one query of type .
Output
For each query of type , print its value.