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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
using namespace std; int T; typedef long long ll;
int n; const int maxn = 1e5+100; ll c[maxn]; int nu[maxn];
int (int x){ return x&(-x); }
void add(int x,int d){ while(x<maxn){ c[x]+=d; x+=lowbit(x); } }
void add1(int x,int d){ while(x<maxn){ nu[x]+=d; x+=lowbit(x); } }
ll sum(int x){ ll ret = 0; while(x){ ret+=c[x]; x-=lowbit(x); } return ret; } int sum1(int x){ int ret = 0; while(x){ ret+=nu[x]; x-=lowbit(x); } return ret; }
typedef pair<int,int> P; P r[maxn]; int k; int q; int num; ll s;
ll check(int x,int yy){ return 1LL*sum1(x)*(x+yy)-sum(x); }
int main(){ scanf("%d",&T); while(T--){ scanf("%d%d",&n,&k); for(int i=0;i<k;i++)scanf("%d%d",&r[i].first,&r[i].second); sort(r,r+k); scanf("%d",&q); while(q--){ scanf("%lld",&s); ll res = 0; num = 0; for(int i=0;i<=n;i++)c[i] = 0,nu[i] = 0; int j = n; for(int i=1;i<=n;i++){ while(r[num].first<=i&&num<k){ add(r[num].second,r[num].second+r[num].first); add1(r[num].second,1); num++; } while(check(j,i)>s&&j){ j--; } if(!j)break; if(check(j,i)==s)res++; } printf("%lld%c",res,!q?'n':' '); } } return 0; }
|
近期评论