标题效果:

给很多分布 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. 【C/C++】BinarySearch

    /* * BinarySearch.c * * Created on: 2014年6月25日 * Author: wenbo */ #include <stdio.h> int binar ...

  2. Android error:No CPU/ABI system image available for this target

    原文:Android error:No CPU/ABI system image available for this target No CPU/ABI system image available ...

  3. Leetcode: Spiral Matrix. Java

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...

  4. windows phone (22) 隐藏元素

    原文:windows phone (22) 隐藏元素 在wp中我们也会用到隐藏某个元素,已达到某种效果,刚刚从文章看到了,分享一下[作者:神舟龙] Visibility 此属性能非常方便的实现隐藏某个 ...

  5. C语言cgi(1)

    1Columbia Universitycs3157 – Advanced ProgrammingSummer 2014, Lab #2, 60ish pointsJune 9, 2014Follow ...

  6. TP-LINK telnet远程 重启路由器(转)

    突然断网,以前房东的路由器管理页面可以打开,今天突然间就打不开了.ping了下,可以ping通,于是就想起了房东的路由器是TP-LINK的 可以 telnet登陆的.每次,断网,我都会重启房东的路由器 ...

  7. [TWRP 2.8.4 ] 小米 3W 中文-英文版本 twrp

    经过半个小时的代码修改,从 2.7.0 移植到 2.8.4 的源代码上. 汉化操作是使用切换语言选项来实现的. 注意: 此版本的 twrp 还不支持双系统切换功能. 作者:laser杨万荣 如果需要转 ...

  8. CentOS 安装memcached

    一,安装libevent 安装位置 /usr/lib #tar -zxvf libevent-2.0.21-stable.tar.gz # cdlibevent-2.0.21 # ./configur ...

  9. 【Java基金会】Java整理面试问题和评论(一)

    1. ArrayList,Vector, LinkedList 存储性能及特点 ArrayList 和 Vector 都是使用数组方式存储数据,此数组元素数大于实际存储的数据以便添加和插入元素,它们都 ...

  10. C++ 习题 输出日期时间--友元函数

    Description 设计一个日期类和时间类,编写display函数用于显示日期和时间.要求:display函数作为类外的普通函数,分别在Time和Date类中将display声明为友元函数.在主函 ...