HDU 4970 killing monsters

Source: Internet
Author: User

In the beginning, I thought it was a line segment tree. I thought it could be too complicated... But this question seems to be stuck in the line segment tree...

Specific Practices:

For each tower, record attack [l] + = D, attack [R + 1]-= D; for each block, the attack is caused by the prefix and attack [1] + attack [2] +... + attack [I];

Traverse from the back to the front to calculate the total damage from the current point to the end;

 

PS: It seems that many people write data in a tree array... I still don't know what the relationship is with the tree array... Orz

 

 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 using namespace std; 5  6 const int maxn = 100005 ; 7  8 long long attack[maxn]; 9 long long sum[maxn];10 11 int main (){12     int n,m,l,r,d,k,x,ans;13     long long h;14     while (~scanf ("%d",&n)&&n){15         memset (attack,0,sizeof attack);16         scanf ("%d",&m);17         while (m--){18             scanf ("%d%d%d",&l,&r,&d);19             attack[l]+=d;20             attack[r+1]-=d;21         }22         long long temp=0;23         for (int i=1;i<=n;i++){24             temp+=attack[i];25             attack[i]=temp;26         }27         temp=0;28         for (int i=n;i>=1;i--){29             temp+=attack[i];30             sum[i]=temp;31         }32         scanf ("%d",&k);33         ans=0;34         while (k--){35             scanf ("%I64d%d",&h,&x);36             if (sum[x]

 

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.