Paste all the line tree lines made in the past few days... to show that they followed HH ,,,
Post a poster, or segment update.
The range is a bit large, and the operation is discretization.
The last few images can be viewed ..
Refer:
# Include <iostream> # include <algorithm> # include <cstdio> # include <cstring> using namespace STD; # define lson l, m, RT <1 # define rson m + 1, R, RT <1 | 1 # define maxn 40005int Li [maxn], RI [maxn]; int res [maxn * 3]; // int Col [maxn <4]; bool hash [maxn]; int CNT; int CMP (const void *, const void * B) {return * (int *) A-* (int *) B;} void Pushdown (INT RT) {If (COL [RT]! =-1) {Col [RT <1] = Col [RT <1 | 1] = Col [RT]; Col [RT] =-1 ;}} void Update (int l, int R, int C, int L, int R, int RT) {If (L> = L & R <= r) {Col [RT] = C; return;} Pushdown (RT); int M = (L + r)> 1; if (L <= m) Update (L, r, C, lson); If (r> m) Update (L, R, C, rson);} int Bin (INT key, int N, int res []) {int L = 0; int r = n-1; while (L <= r) {int M = (L + r)> 1; if (RES [m] = Key) return m; If (Key <= res [m]) r = m-1; else l = m + 1;} return-1 ;} void query (int L, int R, int RT) {If (COL [RT]! =-1) {If (! Hash [col [RT]) CNT ++; hash [col [RT] = true; return;} If (L = r) return; int M = (L + r)> 1; query (lson); query (rson);} int main () {int t; int n, m; scanf ("% d", & T); M = 0; while (t --) {scanf ("% d", & N); For (INT I = 0; I <n; I ++) {scanf ("% d", & Li [I], & Ri [I]); res [M ++] = Li [I]; Res [M ++] = Ri [I];} qsort (Res, M, sizeof (RES [0]), CMP); int T = 1; for (INT I = 1; I <m; I ++) if (RES [I]! = Res [I-1]) RES [t ++] = res [I]; for (INT I = T-1; I> 0; I --) {If (RES [I]! = Res [I-1] + 1) RES [T + +] = res [I-1] + 1;} qsort (Res, T, sizeof (RES [0]), CMP ); memset (COL,-1, sizeof (COL); For (INT I = 0; I <n; I ++) {int L = Bin (Li [I], t, Res); int r = Bin (RI [I], T, Res); Update (L, R, I, 0, T, 1);} CNT = 0; memset (hash, false, sizeof (hash); query (0, T, 1); printf ("% d \ n", CNT);} return 0 ;}