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;}