CF369E Valera and Queries
嘟嘟嘟
这题刚开始以为是一个简单题,后来越想越不对劲,然后就卡住了。
瞅了一眼网上的题解(真的只瞅了一眼),几个大字令人为之一振:正难则反!
没错,把点看成区间,比如2, 5, 6, 9就是[1, 1], [3, 4], [7, 8], [10, INF]。然后只要看给定的哪些线段完全包含在这些区间里了。
预处理出这些区间后,离线下来,按左端点从大到小,右端点从从小到大排序。遇到一个线段就加进树状数组里,遇到一个区间就查一下R的前缀和。因为我们是左端点从大到小扫的,所以一定保证加进树状数组的线段的左端点大于等于当前查询区间的左端点。所以只用考虑右端点即可。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 3e5 + 5;
const int maxN = 1e6 + 5;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
int n, m, Max = 0;
struct Seg
{
int L, R, id;
In bool operator < (const Seg& oth)const
{
if(L ^ oth.L) return L > oth.L;
if(R ^ oth.R) return R < oth.R;
return id < oth.id;
}
}t[maxn << 2];
int cnt = 0, tp[maxn], ans[maxn];
int c[maxN];
In int lowbit(int x) {return x & -x;}
In void add(int pos)
{
for(; pos < maxN; pos += lowbit(pos)) ++c[pos];
}
In int query(int pos)
{
int ret = 0;
for(; pos; pos -= lowbit(pos)) ret += c[pos];
return ret;
}
int main()
{
n = read(); m = read(); cnt = n;
for(int i = 1; i <= n; ++i) t[i].L = read(), t[i].R = read(), t[i].id = 0;
for(int i = 1; i <= m; ++i)
{
int tot = read();
for(int j = 1; j <= tot; ++j) tp[j] = read();
for(int j = 1; j <= tot; ++j)
if(tp[j] > 1 && tp[j - 1] < tp[j] - 1) t[++cnt] = (Seg){tp[j - 1] + 1, tp[j] - 1, i};
t[++cnt] = (Seg){tp[tot] + 1, maxN - 5, i};
}
sort(t + 1, t + cnt + 1);
for(int i = 1; i <= cnt; ++i)
if(t[i].id) ans[t[i].id] += query(t[i].R);
else add(t[i].R);
for(int i = 1; i <= m; ++i) write(n - ans[i]), enter;
return 0;
}
CF369E Valera and Queries的更多相关文章
- CF369E Valera and Queries kdtree
给你一堆线段,求:一个区间内包含的本质不同线段种类数(只要线段有一部分在区间中就算是包含) 考虑容斥:总线段数-被那些没有询问的区间完全覆盖的数量. 用离线+树状数组数点或者 KDtree 数点即可. ...
- [CF369E]Valera and Queries_离线_树状数组
Valera and Queries 题目链接:codeforces.com/problemset/problem/369/E 数据范围:略. 题解: 这种题,就单独考虑一次询问即可. 我们发现,包括 ...
- 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个点中任意一个点的线段的总数. 由于是无修改的,所以我们首先应该往离线上想, 不过我是没想出来. 首先反着做,先求 ...
- cf E. Valera and Queries
http://codeforces.com/contest/369/problem/E 题意:输入n,m; n 代表有多少个线段,m代表有多少个询问点集.每一个询问输出这些点的集合所占的线段的个数. ...
- Codeforces Round #216 (Div. 2) E. Valera and Queries (BIT)
标题效果: 给很多分布 x 行轴. 然后给出了一个非常的多点集,问该组点分布多少不同段. IDEAS: 分散成多个线段点集的. 给出的线段的话,也就是说这个点集上不会有点在这条线段上. 所以我们就是求 ...
- Codeforces 396 E. Valera and Queries
题目链接:http://codeforces.com/problemset/problem/369/E 考虑将问题转化为有多少条线段没有覆盖这些点,如果一个询问的点集是${[x1,x2,...,xn] ...
- CF_216_Div_2
比赛链接:http://codeforces.com/contest/369 369C - Valera and Elections: 这是一个树上问题,用深搜,最开始贪心想得是只加叶子节点,找到一个 ...
随机推荐
- Java io 入门
目录 前言 代码演练 字符流 FileReader,FileWriter: BufferedReader,BufferedWriter: InputStreamReader,OutputStreamW ...
- nginx比apache处理静态文件速度快,但是nginx处理大量并发的php请求时,容易出现502错误,频率大概是多少
首先要明确一点的是502是怎么出现的,为什么会出现502呢? 一般而言,出现502的错误是因为php-cgi连接数不够导致的.举个例子:php-cgi开10个进程,前端发20个请求,每个请求的脚本都s ...
- angular 分页插件的使用
html: <pagination total-items="totalItems" ng-model="currentPage" items-per-p ...
- [ORACLE]ORA-28002 The password will expire within 7 days.将不能登录系统
错误“ORA-28002 The password will expire within 7 days. Cannot logon to the database“当在进程调度器上运行AE程序可能遇 ...
- spring一些简单小注意知识点
Spring 配置详解 <!-- Bean元素:使用该元素描述需要spring容器管理的对象 class属性:被管理对象的完整类名. name属性:给 ...
- 关于处理注册表权限无法修改的问题(无法打开主键或注册表项unknown)
CMD下(管理员) secedit /configure /cfg %windir%\inf\defltbase.inf /db defltbase.sdb /verbose 此命令可以生成报告, 任 ...
- PMS 修改禅道默认首页元素及展示
修改禅道默认首页元素及展示 by:授客 QQ:1033553122 测试环境: 禅道项目管理软件ZenTaoPMS.9.5.1.win64 需求描述 如下,安装禅道后访问默认首页,展示如下,我们希望它 ...
- Angular调用Asp.net Core JWT Authentication接口
基本思路是调用登录接口,获取token,使用token请求其他JWT接口: getHomeDetails(): Observable<HomeDetails> { let headers ...
- 在a标签内添加hover样式的方法:
<a href="javascript:void(0);" onmouseover="this.style.color='yellow';" onmous ...
- Okhttp3请求网络开启Gzip压缩
前沿 首先OkHttp3是支持Gzip解压缩的,不过我们要明白,它是支持我们在发起请求的时候自动加入header,Accept-Encoding: gzip,而我们的服务器返回的时候header中有C ...