HDU-4970 killing monsters

Source: Internet
Author: User


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

Question: "N" indicates the length, "M" indicates the number of towers, and then the HP of each monster and the position where the monster appears. Can this problem be solved?

Idea: prefix processing.

# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; const int maxn = 100005; typedef _ int64 ll; struct node {ll X, Y, D;} node [maxn]; int n, m; ll sum [maxn]; ll CG [maxn]; ll TMP [maxn]; int main () {While (scanf ("% d", & N )! = EOF & N) {scanf ("% d", & M); memset (CG, 0, sizeof (CG); memset (sum, 0, sizeof (SUM); memset (TMP, 0, sizeof (TMP); For (INT I = 1; I <= m; I ++) {scanf ("% i64d % i64d % i64d", & node [I]. x, & node [I]. y, & node [I]. d); CG [node [I]. x] + = node [I]. d; CG [node [I]. Y + 1]-= node [I]. d ;}for (INT I = 1; I <= N; I ++) {sum [I] = sum [I-1] + CG [I];} for (INT I = 1; I <= N; I ++) {TMP [I] = TMP [I-1] + sum [I];} int Q, B; ll A; scanf ("% d", & Q); int ans = 0; For (INT I = 0; I <q; I ++) {scanf ("% i64d % d", & A, & B); If (TMP [N]-TMP [B-1]> =) {ans ++ ;}} printf ("% d \ n", Q-ans) ;}return 0 ;}



Related Article

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.