#FT0000015. Đảo tham lam – Đếm các loại mìn (Greed Island)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đảo tham lam – Đếm các loại mìn (Greed Island)
Greed Island
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
On Greed Island, a defensive line consists of positions. Each deployment selects a consecutive interval and places a completely new type of mine, never used in an earlier deployment, at every position in that interval.
Command 1 l r deploys a new mine type at all positions of the inclusive interval . Previously deployed types remain in place even when intervals overlap; no mine is ever removed.
Command 2 l r counts the number of distinct mine types that occur at least once within the inclusive query interval . A type covering several positions is counted once only. Two separate deployments always represent different types, even if their intervals are identical.
Answer each query at the moment it occurs, considering all earlier deployments.
Input
- Line 1:
n mgives defense-line length and command count. - Next lines: each line contains one of the following commands, in execution order:
1 l r: deploy a new mine type on .2 l r: count distinct mine types covering at least one position of .
Output
For each 2 l r command, print the number of distinct mine types deployed at least at one position in . Print one answer per line in query order.
Subtasks
Subtask 1 (30 points):
- .
- .
- in both operation types.
- Every
1 l rintroduces a new mine type distinct from all previously deployed types.
Subtask 2 (70 points):
- .
- .
- in both operation types.
- Every
1 l rintroduces a new mine type distinct from all previously deployed types.
Examples
Input
5 6
1 1 3
1 3 5
2 2 4
2 4 5
1 2 2
2 2 2
Output
2
1
2
Explanation
There are elements. No mine type has been deployed yet.
-
Command 1 —
1 1 3: Deploy mine type 1 on ; deployed intervals: . -
Command 2 —
1 3 5: Deploy mine type 2 on ; deployed intervals: , . -
Command 3 —
2 2 4: Query ; intersecting mine types: 1, 2. There are distinct types; print2. -
Command 4 —
2 4 5: Query ; intersecting mine types: 2. There are distinct types; print1. -
Command 5 —
1 2 2: Deploy mine type 3 on ; deployed intervals: , , . -
Command 6 —
2 2 2: Query ; intersecting mine types: 1, 3. There are distinct types; print2.
Collect the answers to output-producing commands in their input order, printing one answer per line.