#P2161. [SHOI2009] 会场预约

    ID: 1139 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2009各省省选平衡树树状数组上海

[SHOI2009] 会场预约

Description

There is an empty auditorium in the PP Building that can provide a meeting venue for companies or organizations.

Most of these meetings require several consecutive days (some may require only one day). However, there is only one venue, so the times of different meetings cannot conflict. That is, the end date of the previous meeting must be before the start date of the next meeting. Therefore, to accept a new reservation request, all reservations that conflict with it must be rejected.

In general, if the PP Building has already accepted a venue reservation (for example, from day 1010 to day 1515), then it will not accept any reservation that conflicts with it (for example, from day 1212 to day 1717).

However, sometimes for economic reasons, the PP Building will reject one or even several previously accepted reservations in order to accept a new one. Therefore, the administrator QQ’s notebook often records such information. (For convenience in this problem, all dates are represented by an integer.) For example, if a 1010-day meeting runs from day 9090 to day 9999, then the earliest the next meeting can start is day 100100. (There is a contradiction here; if you cannot understand, please refer to the formal description.)

Recently, the workload has been increasing. The administrator QQ hopes you, a participant in SHTSC, can design a computer system to make the work easier. This system should be able to perform the following two operations:

Operation A: A new reservation is from day startstart to day endend, and all reservations that conflict with it are rejected. When performing this operation, your system should return the number of reservations that were rejected for this new reservation, so QQ can check against the records.

Operation B: Your system should return the current total number of valid reservations.

Input Format

The first line contains a positive integer nn, the number of operations.
Then follow nn lines, each describing one operation, which is one of the two types above.

Output Format

Output nn lines, each with one integer, representing the answer for the corresponding operation.

6
A 10 15
A 17 19
A 12 17
A 90 99
A 11 12
B
0
0
2
0
1
2

Hint

Constraints:
For 100%100\% of the testdata, 1n2×1051 \le n \le 2 \times 10^5, 1lr1051 \le l \le r \le 10^5.

Translated by ChatGPT 5