question: on the 10th anniversary of the 911 incident, the United States established a new defense system. Each point can be automatically defended, but it takes a cool-down time to defend the point after the defense, that is, no defense can be performed during this period. Now there are two more operations: 1. Each time a terrorist attacks a certain range. 2. The Commander inquired about the number of successful defenses at a certain point.
question: Reference http://blog.csdn.net/moorage/article/details/6785726
# Include <iostream> using namespace STD; # define n 20010 struct {int L, R;} attak [N]; /* record the range of each attack */INT def_time [N], def_num [N], attak_num [N];/* def_time records the time when a point can be defended, attacks greater than or equal to this time can be automatically defended */int l, Q, T; int lowbit (int x) {return X & (-x );} void Update (INT POs, int v) {for (INT I = Pos; I <= L; I + = lowbit (I) attak_num [I] + = V ;} int getsum (int pos)/* count the total number of attacks to a certain point */{int sum = 0; For (INT I = Pos; I> 0; i-= lowbit (I) sum + = attak_num [I]; return sum;} int main () {char character [10]; int CS, L, R, Pos; scanf ("% d", & CS); For (INT I = 1; I <= cs; I ++) {int CNT = 0; printf ("case % d: \ n ", I); memset (def_time, 0, sizeof (def_time); memset (def_num, 0, sizeof (def_num); memset (attak_num, 0, sizeof (attak_num); scanf ("% d", & L, & Q, & T); While (Q --) {scanf ("% s ", else); If (else [0] = 'A') {CNT ++; scanf ("% d", & L, & R ); attak [CNT]. L = L; attak [CNT]. R = r; Update (L, 1); Update (R + 1,-1);} else {scanf ("% d", & Pos ); for (INT I = def_time [POS]; I <= CNT; I ++) {If (attak [I]. L <= POS & Pos <= attak [I]. r) {def_num [POS] ++; def_time [POS] = I + T;/* after defense, the next defensive time is I + T */I + = t-1;} printf ("% d \ n", getsum (POS) -def_num [POS]) ;}} return 0 ;}