2014 + schools 1011 -- HDU -- 4097 -- killing monsters (tower guard, line segment tree timeout ..)

Source: Internet
Author: User
Killing monsters

Time Limit: 2000/1000 MS (Java/others) memory limit: 131072/131072 K (Java/Others)
Total submission (s): 107 accepted submission (s): 54


Problem descriptionkingdom rush is a popular TD game, in which you shoshould build some towers to protect your kingdom from monsters. and now another wave of monsters is coming and you need again to know whether you can get through it.

The path of monsters is a straight line, and there are n blocks on it (numbered from 1 to n continuously ). before enemies come, you have m towers built. each tower has an attack range [L, R], meaning that it can attack all enemies in every block I, where l <= I <= R. once a monster steps into block I, every tower whose attack range include block I will attack the monster once and only once. for example, a tower with attack range [1, 3] will attack a monster three times if the monster is alive, one in Block 1, another in Block 2 and the last in Block 3.

A witch helps your enemies and makes every monster has its own place of appearance (the ith monster appears at Block XI). All monsters go straightly to block N.

Now that you know each monster has HP hi and each tower has a value of attack Di, one attack will cause di damage (decrease Hp by DI ). if the HP of a monster is decreased to 0 or below 0, it will die and disappear.
Your task is to calculate the number of monsters grouping ving from your towers so as to make a plan B.


 

Inputthe input contains multiple test cases.

The first line of each case is an integer N (0 <n <= 100000), the number of blocks in the path. the second line is an integer m (0 <m <= 100000), the number of towers you have. the next M lines each contain three numbers, Li, RI, di (1 <= LI <= RI <= N, 0 <di <= 1000 ), indicating the attack range [L, R] and the value of attack D of the ith tower. the next line is an integer K (0 <k <= 100000), the number of coming monsters. the following K lines each contain two integers hi and XI (0 <Hi <= 10 ^ 18, 1 <= xi <= N) indicating the ith monster's live point and the number of the block where the ith monster appears.

The input is terminated by n = 0.


 

Outputoutput one line containing the number of specified ving monsters.


 

Sample Input
521 3 15 5 251 33 15 27 39 10
 


 

Sample output
3HintIn the sample, three monsters with origin HP 5, 7 and 9 will survive. 
Tower defense problems, give the path of N length, M towers, each tower has attack range and Damage Value, give m strange volume and location. A few strange questions can be found that the line segment tree cannot be used throughout the entire process, tree array maintenance, 10000 * log (10000) * Multiple Input groups will definitely time out to define the array C, if the attack range of the I-tower is [L, R] and the damage is D, + D at C [l] And-D at C [R + 1, in this way, from 1 to n, when the value accumulated to k is the total damage that can be received at K points, and then accumulated from N to 1, so that each point stores the total number of injuries from this point to N, as long as the volume of blood exceeds the damage, you can finish, count


 

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define maxn 110000#define LL __int64#define lmin 1#define rmax n#define lson l,(l+r)/2,rt<<1#define rson (l+r)/2+1,r,rt<<1|1#define root lmin,rmax,1#define now l,r,rt#define int_now LL l,LL r,LL rtLL c[maxn] , sum[maxn] ;int main(){    LL n , m , l , r , x , i , temp , num ;    while(scanf("%I64d", &n) && n)    {        num = 0 ;        memset(c,0,sizeof(c));        scanf("%I64dd", &m);        while(m--)        {            scanf("%I64d %I64d %I64d", &l, &r, &x);            c[l] += x ;            c[r+1] -= x ;        }        sum[0] = 0 ;        for(i = 1 ; i <= n ; i++)        {            sum[i] = sum[i-1] + c[i] ;        }        for(i = n-1 ; i >= 1 ; i--)        {            sum[i] = sum[i] + sum[i+1] ;        }        scanf("%I64d", &m);        while(m--)        {            scanf("%I64d %I64d", &x, &l);            if( sum[l] < x )                num++ ;        }        printf("%I64d\n", num);    }    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.