luogu#P16327. 线段
线段
Problem Description
You have a multiset , where each element is a segment. Initially, there are elements, and the -th element is the segment .
Then there are operations. In each operation, a segment is given. We simultaneously check every current element . If it intersects with , then the intersecting part is split out from the original segment, and the remaining parts are added back as new elements, while the original element is removed. The newly added elements do not participate in the current operation, and the segment itself is not added into .
Formally, let and . If , then:
- Add the segment to .
- If , add the segment to .
- If , add the segment to .
- Remove the segment from .
After each operation, output the current number of elements in .
Note that if a newly generated element is identical to an existing one, all copies are kept. Similarly, when an element is removed, only one copy is deleted even if multiple identical copies exist.
Input Format
The first line contains two positive integers , denoting the initial number of elements and the number of operations.
The next lines each contain two positive integers , describing the initial segments .
The next lines each contain two positive integers , describing the segment given in each operation.
Output Format
Print lines, each containing a single integer — the number of elements after the corresponding operation.
5 3
1 1
10 10
3 3
3 3
1 10
2 8
3 10
1 3
7
8
9
10 10
2 9
10 10
2 8
2 5
2 9
2 2
1 10
10 10
2 9
2 2
2 10
1 6
1 10
3 4
2 9
1 9
3 7
2 10
2 10
2 10
11
16
16
28
29
29
34
34
34
34
Hint
Explanation for Sample 1
Initially there are segments: .
For the first operation, the given segment is . The segments intersecting it are . After the operation, both remain unchanged, while becomes . So there are elements in total.
For the second operation, the given segment is . The intersecting elements are . Among them, only changes, becoming . So there are elements in total.
For the third operation, the given segment is . The only intersecting element that changes is , which becomes . So there are elements in total.
Constraints
For all test cases, , , and .
| Subtask | Special Property | Score | |
|---|---|---|---|
| None | |||
| Yes | |||
| None |
- Special property: It is guaranteed that .