HDU 4970 killing monsters

Source: Internet
Author: User

There are several defensive towers on a straight line with a length of N, each of which has an attack range of [L, R], and then the blood volume and location of several monsters are given, the number of questions that can be taken from the appearance position to the end.

For the L, R, and attack power D of the Defense tower entered each time, a [l] + = D, a [R + 1]-= D. Then sum up from 1 to n to calculate the actual damage of each location. Finally, the suffix and are calculated from the end.

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define maxn 100100typedef long long ll;ll a[maxn];int main(){    int n,m;    while(scanf("%d",&n),n)    {        scanf("%d",&m);        int i,j,x,y,z;        memset(a,0,sizeof(a));        for(i=1;i<=m;i++)        {            scanf("%d%d%d",&x,&y,&z);            a[x]+=z;            a[y+1]-=z;        }        for(i=2;i<=n;i++) a[i]+=a[i-1];        for(i=n-1;i>=1;i--) a[i]+=a[i+1];        int k;        scanf("%d",&k);        ll h;        int sum=0;        while(k--)        {            scanf("%I64d%d",&h,&x);            if(a[x]

 

HDU 4970 killing monsters

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.