Welcome to ZOJ
Select Problem
ZOJ Problem Set - 3324

Time Limit: 3 Seconds      Memory Limit: 32768 KB

Mee is the only genius engineer in country Nii who is fond of making machines. One day, when he was working with his research, an amazing idea thrilled through his head and he decided to make a powerful machine which seemed to be able to solve an important problem in his research.

As the picture shown above, the machine is made up of n blocks in a line numbered from 0 to n - 1. Each moment there is one of the two possible actions.

  • A pressure is generated and it makes a certain consecutive blocks lower than where they had been.
  • One of the still existing pressures is released and the effect the pressure made cancels.

The following picture is the situation after a pressure from 0 to 2 and a pressure from 2 to 3.

The following picture is the situation after releasing the first pressure.

During the progress, the blocks in the original position are considered to promise something and are called H-blocks. The consecutive one or more H-blocks even form an H-group. Mee knew that recording the number of H-groups would be extremely helpful. So after each moment, the number of H-groups should be recorded.

But soon he was facing a serious problem. n could be large and there may be no enough material to finish the machine. What's more, it was impossible to manually calculate the number of H-groups. So he wants a program to simulate the machine and record the number of H-groups for him.


The first line is the number of test cases T (T <= 10).

In each case the first line is n and m (1 <= n <= 108, 0 <= m <= 20000), where n is the number of blocks and m is the number of actions. The following m lines are the m actions. Two kinds of expressions exist.

  • p i j means a pressure acted on blocks from number i to j (inclusive, 0 <= i <= j < n).
  • r i j means the pressure acting on blocks from number i to j is released. i and j is always the effective range of an existing pressure (inclusive, 0 <= i <= j < n).


For each case, first print a line "Case #?:" where ? is the case number starting from 1.

Then print the number of H-groups after each action.

Sample Input

6 6
p 2 2
r 2 2
p 3 3
p 2 3
p 2 2
r 2 3
10 3
p 2 7
p 3 6
p 4 5

Sample Output

Case #1:
Case #2:

Author: ZHUANG, Junyuan
Source: The 7th Zhejiang Provincial Collegiate Programming Contest
Submit    Status