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