Rainbow Layer Cakes#6639

Rainbow Layer Cakes

1 second
256 megabytes
Hard (≈1650)

The legendary Master Baker Cornelia Crumble is renowned for her spectacular rainbow layer cakes. These magnificent creations became the talk of the town in the early 1900s, delighting nobles and wealthy patrons across the land.

One wealthy patron commissioned Master Baker Cornelia to create magnificent cakes. Each cake could have up to layers, with each layer featuring frosting of a single vibrant color. Unfortunately, her secret recipe collection was stolen from her bakery, prompting the involvement of top detectives, Sherlock Scones and Dr. Batter, to recover them.

To track down the recipes, the detectives need to know what each cake looked like, as they might have appeared in rival bakeries. To expedite the investigation, Cornelia described how each cake differed from a previous one, identified by a number provided by Sherlock Scones.

Your task is to design an efficient system to store information about the cakes and verify its accuracy by answering queries of the form: "How many different colors of frosting are present on the cake between layers and inclusive?"

Input

The first line contains two integers (1 \le m \le 100\,000) and (1 \le n \le 50\,000), where is the number of frosting layers, and is the number of layer cakes produced.

The next (1 \le k \le 200\,000) lines describe groups. Each group begins with two numbers (1 \le i \le n) and — where is the group number, and is the number of queries describing how the current cake differs from cake , in the following format:

— in the current cake, assign color (1 \le c \le 32) to the interval [l, r].

Each group concludes with a query in the format:

— in the current cake, determine the number of distinct colors in the interval [l, r].

To compute , use the formula x = (i + v) \bmod i, where is the result of the previous second-type query, and is the current group number. Initially, v = 0. It is guaranteed that 1 \le l, r \le m. The cake numbered is a cake with no frosting layers at all. Some cakes may lack certain layers.

Output

For each second-type query, output the result on a separate line.

Examples

Example 1

Loading
Loading