HDU 4031 attack tree Array

Source: Internet
Author: User

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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.