Codeforces Round #216 (Div. 2) E. Valera and Queries (BIT)
标题效果:
给很多分布 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)的更多相关文章
- Codeforces Round #216 (Div. 2) E. Valera and Queries 树状数组 离线处理
题意:n个线段[Li, Ri], m次询问, 每次询问由cnt个点组成,输出包含cnt个点中任意一个点的线段的总数. 由于是无修改的,所以我们首先应该往离线上想, 不过我是没想出来. 首先反着做,先求 ...
- Codeforces Round #184 (Div. 2) E. Playing with String(博弈)
题目大意 两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏 删字符的规则如下: 1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心 2. 删掉该字符,同时,他 ...
- Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)
Problem Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...
- 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 ...
- 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 ...
- Codeforces Round #394 (Div. 2) C.Dasha and Password(暴力)
http://codeforces.com/contest/761/problem/C 题意:给出n个串,每个串的初始光标都位于0(列)处,怎样移动光标能够在凑出密码(每个串的光标位置表示一个密码的字 ...
- Codeforces Round #216 (Div. 2) D. Valera and Fools
题目链接:http://codeforces.com/contest/369/problem/D 注意题意:所有fools都向编号最小的fool开枪:但每个fool都不会笨到想自己开枪,所以编号最小的 ...
- Codeforces Round #216 (Div. 2) B. Valera and Contest
#include <iostream> #include <algorithm> #include <vector> using namespace std; in ...
- Codeforces Round #216 (Div. 2)A. Valera and Plates
#include <iostream> using namespace std; int main(){ int n, m , k; cin >> n >> m & ...
随机推荐
- 学习NodeJS第一天:node.js介绍
Node.JS 前辈 C 程序猿 Ryan Dahl(http://four.livejournal.com/)工程,根据 Google 著名的开源 JavaScript 发动机 V8 对于二次开发 ...
- 怎样从Hadoop安全模式中进入正常模式
问题: 在Hadoop中,新建一个文件夹,报错了,提示mkdir: org.apache.hadoop.hdfs.server.namenode.SafeModeException: Cannot c ...
- 使用Socket沟通
当两台电脑TCP/IP协议进行通讯.平时Socket对象来表示该通信接口的两端,并通过Socket生产I/O流进行网络通信. 其中ServerSocket对象可以接收从连接的其他通信实体的请求.这个目 ...
- 搭建solr单机版
solr单机版的搭建 一.solr单机版的搭建 1.运行环境 solr 需要运行在一个Servlet容器中,Solr4.10.3要求jdk使用1.7以上,Solr默认提供Jetty(ja),本教va写 ...
- Oracle Data Provider for .NET 的使用经验
原文:Oracle Data Provider for .NET 的使用经验 Oracle Data Provider for .NET 是Oracle提供的基于Ado.net接口的一个开发包. ...
- swift 学习资源 大集合
今天看到一个swift学习网站,其中我们收集了大量的学习资源 Swift 介绍 Swift 介绍 来自 Apple 官方 Swift 简单介绍 (@peng_gong) 一篇不错的中文简单介绍 [译] ...
- debain install scim
1. su input root pwd 2. apt-cache search scim apt-get install scim apt-cache search scim-pinyin apt- ...
- 【Jqurey EasyUI+Asp.net】---DataGrid增加、删、更改、搜
在前面写了两,但不知道如何完成,对比刚刚开始学这个,他们摸着石头过河,一步步.在最后两天DataGridCRUD融合在一起.因此份额.我希望像我这样谁是刚刚开始学习一些帮助. 直接主题酒吧. 它是说数 ...
- SPOJ PT07X Vertex Cover
题目意思: 一棵树,找到最少的点能覆盖到所有的边,(也就是每条边俩端 至少有一个在你找到的集合): 解法:每条边只能被俩个点中的一个,或全部覆盖所以我们有树形DP来解: DP[num][flag]// ...
- 隐藏快捷方式扩展名(.lnk)
自从装了Windows 7操作系统以后,有一个问题一直困扰着我.当我去掉“目录选项中”的“隐藏已知文件类型的扩展名”选项的“√”之后,桌面上的快捷方式的扩展名也出来了,看上去非常不爽.记得在XP.Vi ...