#pragma GCC optimize(3)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <stdio.h>
#include <queue>
#include <vector>
#include <string>
#include <set>
#include <map>
#define fi first
#define se second
#define P pair<int,int>
#define sc scanf
#define N 1500050
#define M 300005
#define INF 0x3f3f3f3f
using namespace std;
inline int getmax(int x,int y){return (x>y)?x:y;}
inline int getmin(int x,int y){return (x>y)?y:x;}
int n,m,k,c[N],ans[N],cnt;
struct hh
{
int l,r;
bool operator < (const hh &e) const{return r<e.r;}
}Seg[M];
struct oo
{
int x,pre,order;
bool operator < (const oo &e) const{return x<e.x;}
}point[M*2];
inline int lowbit(int x ){return x &(-x);}
inline void init(int now)
{
for(int i=now;i<N;i+=lowbit(i))
c[i]+=1;
}
inline int query(int now)
{
int ans=0;
for(int i=now;i>=1;i-=lowbit(i))
ans+=c[i];
return ans;
}
int main(int argc, char const *argv[])
{
while(~scanf("%d%d",&n,&m))
{
memset(c,0,sizeof c);
memset(ans,0,sizeof ans);
for(int i=1;i<=n;++i)
scanf("%d%d",&Seg[i].l,&Seg[i].r);
cnt=0;
for(int loc=1;loc<=m;++loc)
{
scanf("%d",&k);
for(int i=1;i<=k;++i)
{
scanf("%d",&point[++cnt].x);
point[cnt].order=loc,point[cnt].pre=-1;
if(i==1) continue;
point[cnt].pre=point[cnt-1].x;
}
point[++cnt].x=1e6+1;
point[cnt].order=loc,point[cnt].pre=point[cnt-1].x;
}
sort(Seg+1,Seg+1+n);
sort(point+1,point+1+cnt);
int now=1;
for(int i=1;i<=cnt;++i)
{
while(Seg[now].r<point[i].x && now<=n)
{
init(Seg[now].l);
now++;
}
ans[point[i].order]+=query(point[i].x-1)-query(point[i].pre);
}
for(int i=1;i<=m;++i)
printf("%d\n",n-ans[i]);
}
return 0;
}
HDU5603--树状数组
最新推荐文章于 2018-05-17 20:34:18 发布