Codeforces 396 E. Valera and Queries
题目链接:http://codeforces.com/problemset/problem/369/E
考虑将问题转化为有多少条线段没有覆盖这些点,如果一个询问的点集是${[x1,x2,...,xn]}$那么相当于询问有多少条线段在${\left [ 1,x1 \right )\bigcup (x1,x2)\bigcup ...(x_{n-1},x_n)\bigcup(x_n,1e6+1)}$这个范围内,所以离线询问,从左至右扫过去,每到一个点就把以这个点为右端点的线段的左端点的位置加入到树状数组中,然后统计答案
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<map>
using namespace std;
#define llg int
#define maxn 1000100
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg ans[maxn],n,m,c[maxn];
vector<llg>q[maxn],belong[maxn],line[maxn]; inline llg getint()
{
llg w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar();
if (c=='-') q=, c=getchar(); while (c>='' && c<='') w=w*+c-'', c=getchar();
return q ? -w : w;
} void inc(llg x) {for (;x<maxn;x+=x&-x) c[x]++;} llg sum(llg x) {if (x==) return ; llg val=; for (;x>;x-=x&-x) val+=c[x]; return val;} void init()
{
cin>>n>>m;
for (llg i=;i<=n;i++)
{
llg l=getint(),r=getint();
line[r].push_back(l);
}
for (llg i=;i<=m;i++)
{
ans[i]=n;
llg k=getint(),x=;
for (llg j=;j<=k;j++)
{
llg wz=getint();
q[wz].push_back(x);
belong[wz].push_back(i);
x=wz;
}
q[].push_back(x);
belong[].push_back(i);
}
} int main()
{
yyj("ds");
init();
for (llg i=;i<=;i++)
{
llg w=q[i].size();
for (llg j=;j<w;j++)
{
ans[belong[i][j]]-=sum(i-)-sum(q[i][j]);
}
w=line[i].size();
for (llg j=;j<w;j++)
{
llg x=line[i][j];
inc(x);
}
}
for (llg i=;i<=m;i++) printf("%d\n",ans[i]);
return ;
}
Codeforces 396 E. Valera and Queries的更多相关文章
- CodeForces - 369E Valera and Queries(树状数组)
CodeForces - 369E Valera and Queries 题目大意:给出n个线段(线段的左端点和右端点坐标)和m个查询,每个查询有cnt个点,要求给出有多少条线段包含至少其中一个点. ...
- Codeforces 369E Valera and Queries --树状数组+离线操作
题意:给一些线段,然后给m个查询,每次查询都给出一些点,问有多少条线段包含这个点集中的一个或多个点 解法:直接离线以点为基准和以线段为基准都不好处理,“正难则反”,我们试着求有多少线段是不包含某个查询 ...
- Codeforces Round #216 (Div. 2) E. Valera and Queries 树状数组 离线处理
题意:n个线段[Li, Ri], m次询问, 每次询问由cnt个点组成,输出包含cnt个点中任意一个点的线段的总数. 由于是无修改的,所以我们首先应该往离线上想, 不过我是没想出来. 首先反着做,先求 ...
- Codeforces Round #216 (Div. 2) E. Valera and Queries (BIT)
标题效果: 给很多分布 x 行轴. 然后给出了一个非常的多点集,问该组点分布多少不同段. IDEAS: 分散成多个线段点集的. 给出的线段的话,也就是说这个点集上不会有点在这条线段上. 所以我们就是求 ...
- codeforces 713A A. Sonya and Queries(状态压缩)
题目链接: A. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input st ...
- codeforces 375D:Tree and Queries
Description You have a rooted tree consisting of n vertices. Each vertex of the tree has some color. ...
- cf E. Valera and Queries
http://codeforces.com/contest/369/problem/E 题意:输入n,m; n 代表有多少个线段,m代表有多少个询问点集.每一个询问输出这些点的集合所占的线段的个数. ...
- CodeForces 441 A. Valera and Antique Items
纯粹练JAVA.... A. Valera and Antique Items time limit per test 1 second memory limit per test 256 megab ...
- [Codeforces 863D]Yet Another Array Queries Problem
Description You are given an array a of size n, and q queries to it. There are queries of two types: ...
随机推荐
- vghyj
2017*****1012:我是康迪:我的爱好是计算机:我的码云个人主页是:https://gitee.com/kdkdkdkd我的第一个项目地址是:https://gitee.com/kdkdkdk ...
- Android编程 控件与布局
控件和布局的继承结构 常用控件 1.TextView <?xml version="1.0" encoding="utf-8"?> <Line ...
- 干了这杯java之ThreadLocal
ThreadLocal Java篇 是什么 怎么用 源码 缺点 总结 是什么 ThreadLocal是一个关于创建线程局部变量的类,这个变量只能当前线程使用,其他线程不可用. ThreadLocal提 ...
- [LeetCode] 132. Palindrome Partitioning II_ Hard tag: Dynamic Programming
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- MySQL InnoDB Online DDL学习
MySQL Online DDL这个新特性是在MySQL5.6.7开始支持的,更早期版本的MySQL进行DDL对于DBA来说是非常痛苦的.现在主流版本都集中在5.6与5.7,为了更好的理解Online ...
- crypto++
CryptoPP库是一个C++书写的加密算法库,很棒. 在如今的抛却数字证书体系下,只关注公私钥对的情况下,我认为存粹的加解密算法库很有市场,虽然我以前觉得PolarSSL的加解密算法实现不错,但不影 ...
- python之单例模式
#单例模式:有时需要写出高性能的类,那么会采用单例模式.通俗的解释就是类只创建一次实例,贯穿整个生命周期,实现了高性能. #1.模块化单例#所谓的模块化就是一个单独的.py文件来存储类,这样就是单例模 ...
- 微信小程序之回调函数
在微信小程序中众所周知在js里面得方法都是异步执行,我最近再做项目得时候也遇到了这个问题,再方法里面调用另一个方法里面的接口数据,第一次是调取不到的, 因为两个方法是同时开始执行得,所以怎么都取不到值 ...
- RSA 汇总
最近工作中遇到了RSA,这个,以前只是粗略的看了一下,结果,实际使用的时候,各种眼花缭乱啊.现在整理一下RSA有哪些相关知识. 1. RSA算法本身.算法本身的内容实际上是在pkcs#1的标准里面说明 ...
- JavaScript自定义事件和触发(createEvent, dispatchEvent)
$(dom).addEvent("ft", function() { alert("走起"); }); // 创建 var evt = document.cre ...