P18101 [CCPC 2026 Changchun] Tape Coloring
Description
There is a paper tape of length $n$, and initially every cell is blank. Little L has $m$ coloring operations, where the $i$-th operation is described by an integer $o_i$ and a position $x_i$:
- If $o_i=0$, change the cells in the position interval $[1,x_i]$ to color $i$;
- If $o_i=1$, change the cells in the position interval $[x_i,n]$ to color $i$.
A color is called visible if and only if at least one cell of the final tape has this color.
Little L wants you to answer $q$ queries:
- Given positive integers $l_j,r_j$, if we start from a blank tape and only perform the $l_j,l_j+1,\dots,r_j$-th operations in order, how many colors are visible on the final tape?
Input Format
The first line contains three integers $n,m,q$ ($1\le n \le 10^9$, $1\le m,q\le 5\times 10^5$), representing the number of cells of the tape, the number of operations and the number of queries.
The next $m$ lines, the $i$-th of which contains two integers $o_i,x_i$ ($o_i\in \{0,1\}$, $1\le x_i\le n$), describe the $i$-th operation.
The next $q$ lines, the $j$-th of which contains two integers $l_j,r_j$ ($1\le l_j\le r_j\le m$), describe the $j$-th query.
Output Format
Output $q$ lines, each with a single integer, where the $j$-th line is the answer to the $j$-th query.
Explanation/Hint
Among the four operations, operation $1$ colors $[1,3]$ with color $1$, operation $2$ colors $[2,5]$ with color $2$, operation $3$ colors the whole tape with color $3$, and operation $4$ colors $[4,5]$ with color $4$.
- Performing only operations $1\sim 4$: the final tape has color $3$ on $[1,3]$ and color $4$ on $[4,5]$. The visible colors are $3,4$, so the answer is $2$.
- Performing only operations $2\sim 3$: operation $3$ covers the whole tape, so only color $3$ is visible at the end, and the answer is $1$.
- Performing only operations $1\sim 2$: at the end cell $1$ has color $1$ and the cells $[2,5]$ have color $2$, so the answer is $2$.
Translated by QwenWork