Nolik and the Game
Time limit2sMemory limit1024 MB
Given n colored cubes with point color updates, answer each range query with the maximum number of distinct colors in any length-k window inside the query range.
- Level
Hard8 of 10
- Topics
- Segment tree, Sliding window, Hash map
- Solved
- No attempts yet
Statement
Nolik found an interesting game on Dim Dimych's phone. Its creators meant it to train reaction speed and attentiveness. For Dim Dimych, it is too hard.
The game works as follows. colored cubes stand in a row on the screen. At some moments the colors of some cubes change. At other times the game asks a question: it gives an interval (), and the player must answer with the maximum number of distinct colors on a segment of length contained in . The number is set at the start of the game and stays fixed throughout. Your goal is to answer every question correctly.
You play the programmer of this game and compute the correct answers to all questions.
Input
The first line contains three integers , , (, , ): the number of cubes, the number of events, and the segment length. The second line contains integers (), the initial colors of the cubes.
Each of the next lines describes one event:
- 1 i x: change the color of the -th cube to (, ).
- 2 l r: answer the question for the interval , where .
Output
For each event of type 2, print the answer on its own line, in the order the questions are asked.