counting--线段树

本文介绍了一种基于线段树的数据结构实现,包括添加、删除线段及区间查询操作。通过对不同类型的线段进行分类讨论,提出了有效的计算方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

 

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.

Input

 

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 ≤ 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.

Output

 

For each query of operation 3, output the answer in one line.

Sample Input
 Copy sample input to clipboard
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
Sample Output
3
2
1
0
3
2
1
0
题意:三种操作:
第一:添加线段
第二:删除线段
第三:询问线段树
对于指定区间,可把全区间分为三段。所有线段分为6种。
区间1->区间1	区间1->区间2	区间1->区间3
区间2->区间2	区间2->区间3	区间3->区间3
题意要求第二+第三+第四+第五种
可以通过目前的线段树-第一种-第六种得到
线段树维护区间的入度和出度。则第一种=第一区间的入度。	第六种=第三区间的出度

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值