Fabergé Eggs
Fabergé eggs are renowned jeweled Easter eggs crafted by the House of Fabergé. These exquisite pieces were made between 1885 and 1917 for the Russian imperial family and select private clients.
One private client commissioned Carl Fabergé to create n valuable eggs. Each egg could have up to m stripes, with each stripe adorned with gemstones of a single color. Unfortunately, the collection was stolen, prompting the involvement of top detectives, Sherlock Holmes and Dr. Watson, to recover them.
To track down the jewels, the detectives need to know their appearance, as they might have surfaced on the black market. To expedite the investigation, the owner described how each jewel differed from a previous one, identified by a number provided by Sherlock Holmes.
Your task is to design an efficient system to store information about the jewels and verify its accuracy by answering queries of the form: "How many different colors of gemstones are present on the ornament between stripes l and r inclusive?"
Input
The first line contains two integers m (1 ≤ m ≤ 100000) and n (1 ≤ n ≤ 50000), where m is the number of gemstone stripes, and n is the number of Fabergé Easter eggs produced.
The next k (1 ≤ k ≤ 200000) lines describe n groups. Each group begins with two numbers i (1 ≤ i ≤ n) and k, where i is the group number, and k is the number of queries indicating how the current item differs from item x, in the format:
l r c - in the current jewel, assign color c (1 ≤ c ≤ 32) to the interval [l, r].
Each group concludes with a query in the format:
l r - in the current jewel, determine the number of distinct colors in the interval [l, r].
To compute x, use the formula: x = (i + v) mod i, where v is the result of the previous second-type query, and i is the current group number. Initially, v = 0. It is guaranteed that 1 ≤ l, r ≤ m. The item numbered 0 is an egg with no gemstone stripes. Some items may lack certain stripes.
Output
For each second-type query, output the result on a separate line.