Question:Here are three numbers: L (1 <= L <= 100000), t (1 <= T <= 30) and O (1 <= O <= 100000 ), indicates a board with a length of L (1 ~ L ),
T color (1 ~ T), then there are O operations, the initial board 1 ~ The color of L is 1,"C a B c" indicates the C color in the range A and B,"P a B" indicates inquiry
The A and B ranges have several different colors.
# Include <stdio. h> # include <iostream> # include <algorithm> # include <string. h> # include <math. h> # define M 100000 # define ll long using namespace STD; struct tree {int L, R, C; // C represents the color. If the interval (L, R) C =-1;} tree [M * 3]; int color [35]; // If [, b] if a certain color K exists in the interval, color [k] = true; void build (INT ID, int L, int R) {tree [ID]. L = L; tree [ID]. R = r; tree [ID]. C = 1; // The initial color is 1if (L = r) return; build (ID * 2, L, (L + r)/2 ); build (ID * 2 + 1, (L + r)/2 + 1, R);} void Update (int id, int L, int R, int CO) {If (tree [ID]. l> = L & tree [ID]. r <= r) // (L, R) completely overwrites the ID node {tree [ID]. C = Co; return;} If (tree [ID]. c> 0) // always wa here {tree [ID * 2]. C = tree [ID * 2 + 1]. C = tree [ID]. c; tree [ID]. C =-1;} tree [ID]. C =-1; // The Int mid = (tree [ID]. L + tree [ID]. r)/2; If (mid> = r) update (2 * ID, L, R, CO); else if (mid <L) update (2 * ID + 1, l, R, CO); else {update (2 * ID, L, mid, CO); update (2 * ID + 1, Mid + 1, R, CO) ;}} void P (int id, int L, int R) {If (tree [ID]. c> 0) {color [tree [ID]. c] = true; return;} If (tree [ID]. L = tree [ID]. r) return; int mid = (tree [ID]. L + tree [ID]. r)/2; If (mid> = r) P (ID * 2, L, R); else if (mid <L) P (ID * 2 + 1, l, r); else {P (ID * 2, L, mid); P (ID * 2 + 1, Mid + 1, R) ;}} int ans (int t) {int ans = 0; For (INT I = 1; I <= T; I ++) if (color [I]) ans ++; return ans;} int N, t, M; int main () {scanf ("% d", & N, & T, & M); char s [2]; int, c, B; build (1,1, n); While (M --) {scanf ("% s", S); If (s [0] = 'C ') {scanf ("% d", & A, & B, & C); If (A> B) Swap (a, B); Update (1, a, B, c) ;}else {scanf ("% d", & A, & B); If (A> B) Swap (A, B ); memset (color, false, sizeof (color); P (1, a, B); printf ("% d \ n", ANS (t ));}} return 0 ;}