1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| 树状数组,区间更新 wa1:sum[]没有清空。。。以及h应该用long long */ #include <bits/stdc++.h> #define N 100007 using namespace std; long long sum[100007],c[100007]; int lowbit(int x){ return x&(-x); } void update(int bit,int a){ while(bit<=N){ c[bit]+=a; bit+=lowbit(bit); } } long long getsum(int x){ long long sum=0; while(x>0){ sum+=c[x]; x-=lowbit(x); } return sum; } int main() { int n,m,l,r,d,k,x; long long ans,h; while(scanf("%d%d",&n,&m)!=EOF&&n!=0){ memset(c,0,sizeof(c)); memset(sum,0,sizeof(sum)); ans=0; for(int i=0;i<m;i++){ scanf("%d%d%d",&l,&r,&d); update(l,d); update(r+1,-d); } for(int i=n;i>0;i--){ sum[i]=sum[i+1]+getsum(i); } scanf("%d",&k); ans=0; for(int i=0;i<k;i++){ scanf("%I64d%d",&h,&x); if(h>sum[x]){ ans++; } } printf("%I64d\n",ans); } return 0; }
|