HDU 4970 (hangdian multi-school #9 1011) Killing monsters)

Source: Internet
Author: User

Address: HDU 4970

Preprocessing is performed first to mark a point at the border of each turret's fire range. Then, you can scan the damage value of each vertex to calculate it. Then, calculate the total damage value from each point to the end point, and save it. Scan it again. Finally, you can directly determine the complexity of O (2 * n ).

The Code is as follows:

#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.