标题效果:

给很多分布 x 行轴。

然后给出了一个非常的多点集,问该组点分布多少不同段。

IDEAS:

分散成多个线段点集的。

给出的线段的话,也就是说这个点集上不会有点在这条线段上。

所以我们就是求出 点集做出的线段包括了多少个给出的线段就能够了。

那么也就是比較l r的大小,排序之后用BIT

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define lowbit(x) (x&(-x))
#define maxn 1000005 using namespace std; struct node
{
int l,r,p;
bool operator < (const node &cmp)const
{
if(l!=cmp.l)return l>cmp.l;
if(r!=cmp.r)return r<cmp.r;
return p<cmp.p;
}
} line[maxn];
int bit[maxn],ans[maxn],n,m,S=1e6+1;
int sum(int x)
{
int res=0;
for(;x;x-=lowbit(x))res+=bit[x];
return res;
}
int add(int x)
{
for(;x<=S;x+=lowbit(x))bit[x]++;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d%d",&line[i].l,&line[i].r);
int T=n,cnt,p,x;
for(int i=1;i<=m;i++)
{
ans[i]=n;
scanf("%d%d",&cnt,&p);
if(p>1)line[++T].l=1,line[T].r=p-1,line[T].p=i;
for(;--cnt;p=x)
{
scanf("%d",&x);
if(x>p+1)line[++T].l=p+1,line[T].r=x-1,line[T].p=i;
}
line[++T].l=p+1,line[T].r=S,line[T].p=i;
}
sort(line+1,line+1+T);
for(int i=1;i<=T;i++)
if(line[i].p)
ans[line[i].p]-=sum(line[i].r);
else add(line[i].r);
for(int i=1;i<=m;i++)printf("%d\n",ans[i]);
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

Codeforces Round #216 (Div. 2) E. Valera and Queries (BIT)的更多相关文章

  1. Codeforces Round #216 (Div. 2) E. Valera and Queries 树状数组 离线处理

    题意:n个线段[Li, Ri], m次询问, 每次询问由cnt个点组成,输出包含cnt个点中任意一个点的线段的总数. 由于是无修改的,所以我们首先应该往离线上想, 不过我是没想出来. 首先反着做,先求 ...

  2. Codeforces Round #184 (Div. 2) E. Playing with String(博弈)

    题目大意 两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏 删字符的规则如下: 1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心 2. 删掉该字符,同时,他 ...

  3. Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)

    Problem  Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...

  4. Codeforces Round #394 (Div. 2) E. Dasha and Puzzle(分形)

    E. Dasha and Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #267 (Div. 2) C. George and Job(DP)补题

    Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...

  6. Codeforces Round #394 (Div. 2) C.Dasha and Password(暴力)

    http://codeforces.com/contest/761/problem/C 题意:给出n个串,每个串的初始光标都位于0(列)处,怎样移动光标能够在凑出密码(每个串的光标位置表示一个密码的字 ...

  7. Codeforces Round #216 (Div. 2) D. Valera and Fools

    题目链接:http://codeforces.com/contest/369/problem/D 注意题意:所有fools都向编号最小的fool开枪:但每个fool都不会笨到想自己开枪,所以编号最小的 ...

  8. Codeforces Round #216 (Div. 2) B. Valera and Contest

    #include <iostream> #include <algorithm> #include <vector> using namespace std; in ...

  9. Codeforces Round #216 (Div. 2)A. Valera and Plates

    #include <iostream> using namespace std; int main(){ int n, m , k; cin >> n >> m & ...

随机推荐

  1. poj3694(动态询问割桥的数目)

    给我们一个图,然后有q次加边的操作,问每次加完边之后有多少个桥存在 首先用dfs求出所有的桥,然后dfs的过程中生成了一棵dfs树,该树有的边是桥,有的不是,用bridge[v] = true , 表 ...

  2. C# 制作Java +Mysql+Tomcat 环境安装程序,一键式安装

    原文:C# 制作Java +Mysql+Tomcat 环境安装程序,一键式安装 要求: JDK.Mysql.Tomcat三者制作成一个安装包, 不能单独安装,安装过程不显示三者的界面, 安装完成要配置 ...

  3. Android 权限添加

    在AndroidMainFest.xml中加上以下代码就行了 添加WiFi以及访问网络的权限: <uses-permission android:name="android.permi ...

  4. OpenCV, color reduction method

    转载请注明出处!!!http://blog.csdn.net/zhonghuan1992 OpenCV, colorreduction method 目标: 这次学习的目标是回答以下的几个问题: 1 ...

  5. hdu3037(lucas定理)

    给定n,m,p   表示<=m个豆子放在n棵树上,一共有多少种方案数,  总的方案书mod p 如果将m个豆子放在n棵树上, 可以使用插板法 得到方案数是C(n+m-1,n-1) 那么将0< ...

  6. Oracle Data Provider for .NET 的使用经验

    原文:Oracle Data Provider for .NET 的使用经验 Oracle Data Provider for .NET 是Oracle提供的基于Ado.net接口的一个开发包.    ...

  7. ArrayList实现借壳

    随着Collections工具: import java.util.ArrayList; import java.util.Collections; public class TTEST { publ ...

  8. 蚁群算法和简要matlab来源

    1 蚁群算法原理 从1991由意大利学者 M. Dorigo,V. Maniezzo 和 A. Colorni 通过模拟蚁群觅食行为提出了一种基于群体的模拟进化算法--蚁群优化.极大关注,蚁群算法的特 ...

  9. 执行Sql块

    import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import oracle.C ...

  10. 我的CSDN之路

    经营CSDN博客刚满一年,能够说CSDN给我们带来了非常大的帮助,这一年里CSDN见证了我们的成长.以下两篇博客就是我这一年在CSDN的缩影. 这篇是我一年前写的,那时候刚申请CSDN不久:http: ...