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]