标题效果:

给很多分布 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. viewpager与子view的事件冲突解决

    问题: 对android的事件机制一直不怎么了解,最近android项目中运用viewpager+listview (就是viewpager的子view中嵌套了listview),出现了触摸手势冲突 ...

  2. 在Amazon AWS RHEL 7上安装 配置PPTP VPN

    0 前言 0.1 为什么需要VPN? 国内的VPN不是必须,但是国外的VPN是很有用的.连接到国外的VPN服务器之后就可以访问Google,Facebook, Youtube等网站,没有Google的 ...

  3. iOS_8_键盘操作简单

    最后效果图: BeyondViewController.h // // BeyondViewController.h // 9_键盘的简单处理 // // Created by beyond on 1 ...

  4. 解决wordpress发表文章,照片不能居中的问题

    最近,随着一个年轻漂亮的女人的帮助(简直美极了.图相当火爆,性格非常好.大家闺秀型,照片给大家看看下一个突发.哈哈)获取她的个人博客,地址似乎是www.okaaok.com遇到发表文章.照片不能反正水 ...

  5. AndroidUI组件之ListView小技巧

    android:fadingEdge="none"//出去黑影  android:listSelector="@android:color/transparent&quo ...

  6. hdu 4557 非诚勿扰 vector的应用 原来vector 可以删除指定位置元素 不过消耗大

    非诚勿扰 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submi ...

  7. sql语句中单引号嵌套问题

    在sql语句中,我们难免会用到单引号嵌套的时候,但是直接嵌套肯定是不行的,java中用反斜杠做转义符也是不行的,在sql中是用单引号来做转义符的. 比如下面例子是存储过程里查询时的语句示例 exec ...

  8. J2SE习题(2)

    第四.五周练习题 1.a. Define a class called BlogEntry that could be used to store an entry for a  Weblog. Th ...

  9. SqlServer表EXCEL数据复制的另一种方法

    一个.SqlServer表中的数据复制到excel 1.新建查询,用sql语句把表数据读出来 2.然后,选择数据,右键.复制(也能够点击连同标题复制),拷贝到记事本中(不然会乱码) 3.然后再把记事本 ...

  10. composite template 组合模式

      1. 主要优点 组合模式的主要优点如下: (1) 组合模式可以清楚地定义分层次的复杂对象,表示对象的全部或部分层次,它让客户端忽略了层次的差异,方便对整个层次结构进行控制. (2) 客户端可以一致 ...