Update the color in the interval
Total number of colors in the output range
# Include <stdio. h> # include <string. h> # include <stdlib. h> # include <string> # include <iostream> # include <algorithm> # include <sstream> # include <math. h> using namespace STD; # include <queue> # include <stack> # include <vector> # include <deque> # include <set> # include <map> # define CLer (ARR, Val) memset (ARR, Val, sizeof (ARR) # define in freopen ("in.txt", "r", stdin); # define out freopen ("out.txt", "W ", stdout ); Typedef long ll; const int maxn = 5040; // maximum number of points const int maxm = 20006; // maximum number of sides const int INF = 0x3f3f3f; const int mod = 10000007; # define lson L, M, RT <1 # define rson m + 1, R, RT <1 | 1 # define mid (L + r)> 1 # define maxn 1100000int sum [maxn <2], Col [maxn <2]; int num [34]; void pushup (int rt) // update {sum [RT] = sum [RT <1] | sum [RT <1 | 1];} void Pushdown (int rt) {If (COL [RT]) // update {Col [RT <1] = Col [RT <1 | 1] = Col [R T]; sum [RT <1] = sum [RT <1 | 1] = sum [RT]; Col [RT] = 0 ;}} void build (int l, int R, int RT) {sum [RT] = num [2]; // The initial color is 1 If (L = r) {return ;} int M = mid; build (lson); Build (rson); pushup (RT);} void Update (int l, int R, int C, int L, int R, int RT) {If (L <= L & R <= r) {sum [RT] = num [c]; Col [RT] = num [c]; return;} Pushdown (RT); int M = mid; If (L <= m) Update (L, R, C, lson); If (r> m) update (L, R, C, rson); pushup (RT);} int query (int l, int R, int L, int R, int RT) {If (L <= L & R> = r) {return sum [RT];} Pushdown (RT ); int M = mid; int res = 0; If (L <= m) RES = res | query (L, R, lson); If (r> m) res = res | query (L, R, rson); Return res;} int main () {int N, Q; memset (Num, 0, sizeof (Num )); num [1] = 1; for (INT I = 2; I <= 30; I ++) // store each color first... Num [I] = num [I-1] <1; // In; while (scanf ("% d", & N, & Q), N + q) {build (1, n, 1); While (Q --) {char s [3]; scanf ("% s", S); int A, B, C; if (s [0] = 'q') {int ans [33], Wei = 1, point = 0; scanf ("% d", &, & B); int x = query (A, B, 1, n, 1); While (x) // counts the number of colors {If (X & 1 = 1) ans [point ++] = Wei; X = x> 1; Wei ++;} For (INT I = 0; I <point; I ++) printf ("% d % C", ANS [I], I = point-1? '\ N': '');} else {scanf (" % d ", & A, & B, & C); Update (A, B, c, 1, n, 1) ;}} return 0 ;}
[Line Segment tree] HDU 5025 a lost upt mayor's performance art