There are three operations in the axis, which are:
1. Draw a segment in the axis between points a and b (a < b). a and b are all integers.
2. Erase the one existing segment which was drawn before. Suppose that erasing one segment do not affect the other segments in the axis.
3. Count the number of segments between c and d (c < d). c and d are all integers. A segment ab is between c and d iff a < d and c < b.
Given a sequence of such operations, you are to count the number of segments when the operation 3 comes.
The first line of input contains a number representing the number of test cases.
Each test case consists of several lines (at most 100000 lines). Each line begins with an integer k (1 ≤ k ≤3). When k is 1, two integers a and b follow. When k is 2, an integer i follows. It means that you are the erase the i-th segment drawing in the axis. When k is 3, two integers c and d follow. Each test case is end by a 0.
For each query of operation 3, output the answer in one line.
2 1 10 15 1 1 25 1 3 13 3 2 11 2 2 3 2 11 3 13 15 3 15 16 0 1 10 15 1 1 25 1 3 13 3 2 11 2 2 3 2 11 3 13 15 3 15 16 0
3 2 1 0 3 2 1 0
题意:三种操作:
第一:添加线段
第二:删除线段
第三:询问线段树
对于指定区间,可把全区间分为三段。所有线段分为6种。
区间1->区间1 区间1->区间2 区间1->区间3
区间2->区间2 区间2->区间3 区间3->区间3
题意要求第二+第三+第四+第五种
可以通过目前的线段树-第一种-第六种得到
线段树维护区间的入度和出度。则第一种=第一区间的入度。 第六种=第三区间的出度