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: ...
随机推荐
- C++ MFC万能的类向导
MFC的类向导 只要你掌握了类向导,你基本就已经掌握了MFC了,毕竟布局和代码都是自动生成,再加上C++基础上手还是挺快的,剩下的就是多多练习了. 转自: https://blog.csdn.net/ ...
- git使用手册整理
-------------------20181217------------------- git使用:在gitbash 下初始化用户: $ git config --global user.nam ...
- log4j2配置ThresholdFilter,让info文件记录error日志
日志级别: 是按严重(重要)程度来分的(如下6种): ALL < TRACE < DEBUG < INFO < WARN < ERROR < FATAL < ...
- 光圈,快门, 曝光,焦距, ISO,景深。
光圈,快门, 曝光,焦距, ISO,景深. ISO(感光度)与图片质量 ISO -- 感光度,是一个曝光率极高的词,我们在超市买饼干的时候就可能会看见包装袋上写:本公司已通过ISO9001质量体系认证 ...
- 如何运用git实现版本控制
https://git-scm.com/download/win git版本控制器下载地址(64位.32位) 官网地址:https://github.com/ Git账号:applepear456 ...
- vs2017 git凭证问题
安装完tfs2017(自带git)后,连接git代码服务器,报authorication错误.这是vs2017的bug.尝试了许多种方案后,最简单的干脆手动添加如下3个凭证.一定要核对好地址中的. ...
- 使用jconsole监控JVM内存
首先声明:此篇博文分析的是JDK1.8. JVM内存区域总体分两类:heap区和非heap区.Jconsole中对内存划分为同样的结构,如下: heap区又分为: - Eden Space(伊甸园) ...
- Mysql复制一个数据库到另一个数据库
mysqldump -u root -p source_db > /home/db_bak.sql #导出数据库 123456 #输入数据库密码 扩展: mysqldump -u root -p ...
- python函数部分----函数初识
0.来源http://www.cnblogs.com/jin-xin/articles/8241942.html 1.return 返回0个返回值,返回一个返回值.返回多个返回值 None.如果一个变 ...
- day07数据类型的相互转化,字符编码
复习 ''' 1.深浅拷贝 ls = [1, 'a', [10]] 值拷贝:直接赋值 ls1 = ls, ls中的任何值发生改变,ls1中的值都会随之改变 浅拷贝:通过copy()方法 ls2 = l ...