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: 这是一个树上问题,用深搜,最开始贪心想得是只加叶子节点,找到一个 ...
随机推荐
- constructor C++ example
The constructor for this class could be defined, as usual, as: Rectangle::Rectangle (int x, int y) ...
- Android Studio 学习(五)网络
HttpURLConnection OkHttp 添加依赖 编辑 app/build.gradle 在dependencies闭包中添加 implementation 'com.squareup.ok ...
- Request method 'POST' not supported错误和解决方法
在使用SpringBoot的时候,在html页面用form表单post提交数据的时候报错: Request method 'POST' not supported 错误解析: 我是用的前端页面是HTM ...
- 详解Parcel:快速,零配置web应用打包工具。
译者按: 新一代Web应用打包工具Parcel横空出世,快速.零配置的特点让人眼前一亮. 原文: Everything You Need To Know About Parcel: The Blazi ...
- nodeJs express mongodb 建站(mac 版)
基本环境 homebrew.node.npm.express.mongodb 1.node .npm : (1)辅助工具:homebrew安装(mac下一个软件管理工具,相当于Red hat的yum, ...
- 【代码笔记】Web-Javascript-Javascript typeof
一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- Redis 保护模式
默认 redis 启用了保护模式,即如果是远程链接不能进行 CRUD 等操作,如果进行该操作报错如下 (error) DENIED Redis is running in protected mode ...
- C程序
/* 不适用C库函数,只是用 C 语言实现函数 void* memcpy( void *dst, const void *src, size_t len ) memmove 函数的功能是拷贝 src ...
- (网页)websocket后台调用Service层
百度论坛里面有很多好的方法,借鉴. 重点:因为项目是StringBoot所以我用的是下面的方法很好使: Service.... service = (Service....) ContextLoade ...
- svn状态与常见错误
TortoiseSVN 1.6.16是最后一个目录独立管理自身cache的svn版本(每个目录下都有一个隐藏的.svn文件夹) 之后的版本会则会根目录上统一进行管理(只有根目录下有一个隐藏的.svn文 ...