#P1558. 色板游戏

色板游戏

Description

The color board has length LL, where LL is a positive integer, so we can evenly divide it into LL small squares, each 11 centimeter long, labeled from left to right as 1,2,,L1, 2, \dots, L.

Currently the board has only one color. The teacher tells Abao that only two operations are allowed on the board:

  1. C A B C means to paint all squares numbered from AA to BB with color CC.
  2. P A B means a query: how many different colors appear among squares numbered from AA to BB.

There are TT types of paint in the school’s paint box. For simplicity, we label them as 1,2,,T1, 2, \dots, T. Initially, the entire board has color 11. Facing such a complex problem, Abao asks for your help. Can you help him?

Input Format

The first line contains 33 integers LL (1L105)(1 \le L \le 10^5), TT (1T30)(1 \le T \le 30), and OO (1O105)(1 \le O \le 10^5). Here OO is the number of operations.

Then follow OO lines, each describing an operation in the form C A B C or P A B (here A,B,CA, B, C are integers; it is possible that A>BA > B, in which case you should swap AA and BB).

Output Format

For each query from the teacher, output the corresponding answer. Print one integer per line.

2 2 4
C 1 1 2
P 1 2
C 2 2 2
P 1 2
2
1

Hint

Constraints

1L1051 \le L \le 10^5, 1T301 \le T \le 30, 1O1051 \le O \le 10^5.

1A,BL1 \le A, B \le L (not guaranteed that ABA \le B), 1CT1 \le C \le T.

Translated by ChatGPT 5