#FT0000129. Những nét vẽ bằng bút sáp (Crayon)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những nét vẽ bằng bút sáp (Crayon)
Crayon
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Mary maintains a collection of closed intervals on a number line, initially empty. Process operations in order:
D L R: draw a new interval ; each drawn interval is assigned the next 1-based draw identifier.C I: erase the interval whose draw identifier is . It is guaranteed to exist and not have been erased before.Q L R: count the currently active drawn intervals intersecting the closed query interval at one or more points.
Identical intervals with different draw IDs count separately. Touching endpoints are intersections. C I erases only that particular drawing.
Input
- First line: the number of operations .
- Next lines: one operation
D L R,C I, orQ L Rper line.
Output
For each Q operation, print the number of active drawn intervals intersecting the query interval.
Subtasks
- Subtask 1 (20 points): ; Every interval satisfies ;
C Irefers to an existing not-yet-erased drawn interval. - Subtask 2 (30 points): ; Every interval satisfies ;
C Irefers to an existing not-yet-erased drawn interval. - Subtask 3 (50 points): ; Every interval satisfies ;
C Irefers to an existing not-yet-erased drawn interval.
Examples
Example 1
Input
6
D 1 3
D 2 4
Q 2 3
D 2 4
C 2
Q 2 3
Output
2
2
Explanation
The first two drawings are #1 = and #2 = , so query intersects both: output 2. Drawing #3 is another . C 2 removes only drawing #2. Drawings #1 and #3 remain and both intersect , so the second query also returns 2.
Example 2
Input
7
D 1 2
D 5 9
Q 3 4
Q 2 5
C 1
Q 1 2
Q 8 10
Output
0
2
0
1
Explanation
The first two drawings are and . Query intersects neither; query touches both endpoints and intersects both. After erasing drawing #1, query returns 0, while still intersects drawing #2 and returns 1.