[Question] Tower anti-DDoS game, with N-long roads, has m gunshots, which can cover the range of [Li, Ri] and power ci, that is, every second, the turret can cause CI point damage to monsters in the range. There are only Q monsters, each of which has hi-point blood, and the position is Xi. When the monster's blood volume is reduced to 0 or less, the monster keeps moving toward n. Ask how many monsters can leave this path.
[Problem solution] We can use a line segment tree, but fortunately we have a QQ brush algorithm from generation to generation, making the solution much simpler ~ Pai_^
1 # Include <iostream> 2 # Include <cstdio> 3 # Include <cstring> 4 # Include <cmath> 5 # Include <algorithm> 6 7 Using Namespace STD; 8 _ Int64 num [ 100005 ]; 9 10 Struct Node {__ int64 HP, X;} m [ 100005 ]; 11 12 Int CMP (node A, Node B) 13 { 14 Return A. x < B. X; 15 } 16 17 Int Main () 18 { 19 Int N, K, a, B, d; 20 While (~ Scanf (" % D " ,& N), n) 21 { 22 Scanf ( " % D " ,& K ); 23 Memset (Num, 0 , Sizeof (Num )); 24 While (K -- ) 25 { 26 Scanf ( " % D " , & A, & B ,& D ); 27 Num [a] + = D; 28 Num [B + 1 ]-= D; 29 } 30 _ Int64 sum = 0 ; 31 For ( Int I = 0 ; I <= N; I ++ ) 32 { 33 Sum + = Num [I]; 34 Num [I] = SUM; 35 } 36 // Num [I]: Attack Strength at each point I 37 Scanf ( " % D " ,& K ); 38 For ( Int I = 0 ; I <K; I ++ ) 39 Scanf ( " % I64d % i64d " , & M [I]. HP ,& M [I]. X ); 40 Sort (M, M + K, CMP ); 41 Sum = 0 ; 42 Int Ans = 0 , J = k- 1 ; 43 For ( Int I = N; I> = 0 ; I -- ) 44 { 45 Sum + = num [I]; // Sum: The total attack strength from point N to point I 46 While (I = m [J]. X) // Several Monsters may have emerged from point I. 47 { 48 If (M [J]. HP> Sum) 49 Ans ++ ; 50 J -- ; 51 If (J < 0 ) 52 Break ; 53 } 54 If (J < 0 ) 55 Break ; 56 } 57 Printf ( " % D \ n " , ANS ); 58 } 59 Return 0 ; 60 }