F1ow3rC0n
Time limit1sMemory limit512 MB
Maintain an array of flower types under point updates and range queries. For each query, find the minimum number of glue bottles needed to attach petals to trees A through B in order, where each bottle covers one color but can be bought and discarded at will.
- Level
Hard8 of 10
- Topics
- Segment tree, Array, Math, Dynamic programming
- Solved
- No attempts yet
Problem
Taeyoung visited Sejong Lake Park during Humanities and Arts Exploration Week, took photos, and picked petals from a tree to use later. He later learned that picking petals from this tree was not allowed. So Taeyoung made a plan to glue the petals back onto the tree with glue.
Sejong Lake Park has trees in a row, and the type number of the flower on the -th tree is . Taeyoung will glue petals onto the trees over days as follows.
On the -th day, one of the following two events occurs.
- Taeyoung uses glue to attach petals to trees in order.
- The type number of the flower on tree changes to .
While examining the structure of the petals, Taeyoung realized that the glue type number must match the flower type number on the tree, and on the -th day he decided to attach petals to glue as follows. Each day, Taeyoung starts out holding no glue.
- Taeyoung attaches petals to trees through in order. Note that the order of attaching petals is fixed.
- If Taeyoung is not holding glue, he can buy one bottle of glue of any type he wants.
- If Taeyoung is holding glue, he can throw that glue away.
- Taeyoung can attach a petal only when the type number of the flower on the tree he wants to attach it to equals the type number of the glue he is holding.
Taeyoung wonders, for each day he attaches petals, what is the minimum number of bottles of glue he must buy.
Input
The first line gives the number of trees and the number of days on which Taeyoung attaches petals, separated by a space.
The second line gives the flower type number of each tree, , separated by spaces.
The -th of the following lines gives the type of event and the values , for the event, separated by spaces.
- If , petals are attached to trees through in order.
- If , the type number of the flower on tree changes to .
Output
For each day with , print the minimum number of bottles of glue that must be bought, one per line.
Constraints
- ()
- ()
- When , ()
- When , ()
- When , ()
- There is at least one with . ()