Mr.Bridge and Tree Planting
题号:NC244831
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

Mr.Bridge has got many seeds,wow!

Mr.Bridge wanted to plant his seeds into his garden,he asked his firend Mr.house for some advice.

Mr.house is an expert in biology,he found that these seeds can grow into trees,and they will grow up in this way:

At first each tree has one node,which is called "growing node".

Every time it grows,there will be a new node appears above the growing node and connect with the growing node by an edge.Then the growing node move up to the new node.

But sometimes strange things can happen to some trees: its growing node move to the node under it.We called it "growing drop".

Mr.Bridge was happy to know how the tree grows,and he planted n seeds in a row,numbered from 1 to n.

Then m days has pasted.

Everyday one of the following things happened:

1.All trees which numbered from l to r growed.

2.All trees which numbered from l to r "growing droped".

3.Mr.Bridge came to watch them happily.He got close to the i -th tree and wondered how many nodes are in its growing node's subtree.(If node A can be reached from node B only by moving up,we call "node A is in node B 's subtree")

Every time when a tree drops there will be at least one node that is not in its growing node's subtree.

Please help Mr.Bridge to count the number of nodes.

输入描述:

In the first line there are two integers  and ,separated by spaces,which represent the number of trees and the days pasted.

Then there are m lines,each line will be one of following types:

which means all trees numbered from l to r growed.

which means all trees numbered from l to r "growing droped".

which means Mr.Bridge wondered how many nodes are in i-th tree's growing node's subtree.

输出描述:

Output has m lines in total, and the i-th line represents the number of answer to Mr.Bridge's i-th wonder.
示例1

输入

复制
3 3
1 2 3
2 2 3
3 2

输出

复制
2

说明

In this part we define up and down like this:

Here is what the trees are look like when Mr.Bridge planted his seeds.

After day1,here it is.

After day2,herer it is.

On day3,this is what Mr.Bridge wanted to count.