#P1558. Colorful Board Operations
Colorful Board Operations
Colorful Board Operations
We are given a board of length \(L\) centimeters, where \(L\) is a positive integer. The board is divided into \(L\) segments of 1 cm each, numbered from \(1\) to \(L\). Initially, the entire board is painted with color \(1\). There are \(T\) available colors, labeled \(1, 2, \dots, T\). You are allowed to perform the following two types of operations:
C A B C
: Paint the segments from \(A\) to \(B\) with the color \(C\) (the new color to be applied).P A B
: Query how many distinct colors appear in the segments from \(A\) to \(B\).
Your task is to process a sequence of such operations and output the answer for every query operation.
Input Format: The first line contains three integers \(L\), \(T\), and \(N\) (the number of operations). The following \(N\) lines each contain an operation in one of the two formats described above. It is guaranteed that in a paint operation C A B C
, \(1 \leq A \leq B \leq L\) and the color \(C\) is between \(1\) and \(T\). Similarly, in a query operation P A B
, \(1 \leq A \leq B \leq L\).
inputFormat
The first line contains three integers \(L\), \(T\), and \(N\) separated by spaces, where:
- \(L\) is the length of the board (number of 1 cm squares).
- \(T\) is the total number of colors.
- \(N\) is the number of operations.
Each of the next \(N\) lines contains an operation in one of the following two formats:
C A B C
— Paint the segments from \(A\) to \(B\) with color \(C\).P A B
— Query the number of distinct colors from segment \(A\) to \(B\).
outputFormat
For each query operation P A B
, output a single line with the number of distinct colors in the inclusive range from \(A\) to \(B\).
sample
5 3 5
P 1 5
C 2 4 2
P 1 5
C 3 5 3
P 1 5
1
2
3
</p>