D - Mayor's posters POJ - 2528 离散化+线段树 区间修改单点查询
题意 贴海报 最后可以看到多少海报
思路 :离散化大区间 其中[1,4] [5,6]不能离散化成[1,2] [2,3]因为这样破坏了他们的非相邻关系 每次离散化区间 [x,y]时 把y+1点也加入就行了
注:参考了上海全能王csl的博客!
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
#include<cstring>
#include<iostream>
using namespace std;
#define X first
#define Y second
const int maxn=+;
pair<int,int>a[maxn*];
vector<int>v;
struct Node{
int l,r;
int col;
int lazy;
void update(int x){
col=x;
lazy=x;
}
}tree[maxn*];
bool vis[maxn*];
/*void push_up(int x){
if(tree[x<<1].col!=tree[x<<1|1].col||tree[x<<1].col==-1||tree[x<<1|1].col==-1)tree[x].col=-1;
}*/ void build(int x,int l,int r){
tree[x].l=l,tree[x].r=r;
tree[x].col=-;
if(l==r){
return ;
}
else {
int mid=l+r>>;
build(x<<,l,mid);
build(x<<|,mid+,r);
}
} void push_down(int x){
if(tree[x].col==-)return;
tree[x<<].col=tree[x<<|].col=tree[x].col;
tree[x].col=-;
}
void update(int x,int l,int r,int val){
int L=tree[x].l,R=tree[x].r;
if(l<=L&&R<=r){
tree[x].col=val;
return ;
}
else {
push_down(x);
int mid=(L+R)>>;
if(l<=mid)update(x<<,l,r,val);
if(mid<r)update(x<<|,l,r,val);
// pudh_up(x);单点查询不需要合并
}
}
long long query(int x,int a){
int L=tree[x].l,R=tree[x].r;
if(L==R)return tree[x].col;
push_down(x);
int mid=L+R>>;
if(mid>=a)query(x<<,a);
else if(mid<a)query(x<<|,a);
} int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
memset(vis,,sizeof(vis));
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d%d",&a[i].X,&a[i].Y);
v.push_back(a[i].X);
v.push_back(a[i].Y);
v.push_back(a[i].Y+);
}
sort(v.begin(),v.end());
int num=unique(v.begin(),v.end())-v.begin();
for(int i=;i<n;i++){
a[i].X = lower_bound(v.begin(), v.begin() + num, a[i].X) - v.begin() + ;
a[i].Y = lower_bound(v.begin(), v.begin() + num, a[i].Y) - v.begin() + ;
}
build(,,num);
for(int i=;i<n;i++){
update(,a[i].X,a[i].Y,i+);
}
int ans=;
for(int i=;i<=num;i++){
int col=query(,i);
// cout<<col<<endl;
if(col!=-&&vis[col]==){
vis[col]=;
ans++;
}
}
printf("%d\n",ans);
}
return ;
}
D - Mayor's posters POJ - 2528 离散化+线段树 区间修改单点查询的更多相关文章
- HDU 5861 Road(线段树 区间修改 单点查询)
Road Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- ZOJ 1610 Count the Colors【题意+线段树区间更新&&单点查询】
任意门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Count the Colors Time Limit: 2 ...
- POJ - 2528 Mayor's posters (离散化+线段树区间修改)
https://cn.vjudge.net/problem/POJ-2528 题意 给定一些海报,可能相互重叠,告诉你每个海报的宽度(高度都一样的)和先后叠放顺序,问没有被完全盖住的有多少张? 分析 ...
- POJ 2528 Mayor's posters(线段树,区间覆盖,单点查询)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45703 Accepted: 13239 ...
- POJ 3468 A Simple Problem with Integers(线段树区间修改及查询)
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...
- HDU 5861 Road 线段树区间更新单点查询
题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Road Time Limit: 12000/6000 MS (Java/Othe ...
- hdu 1166 敌兵布阵 线段树区间修改、查询、单点修改 板子题
题目链接:敌兵布阵 题目: C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视 ...
- ZOJ 1610 Count the Colors(线段树,区间覆盖,单点查询)
Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on ...
随机推荐
- [C#] LINQ之GroupBy
声明:本文为www.cnc6.cn原创,转载时请注明出处,谢谢! 本文作者文采欠佳,文字表达等方面不是很好,但实际的代码例子是非常实用的,请作参考. 一.先准备要使用的类: 1.Person类: cl ...
- JSF生存指南P1
这是OO的第三次博客作业,也是JSFO(面向JSF编程)的第一次博客作业.暗示了我们面向对象课程已经再向JSF的编写过渡. 不知不觉OO的作业已经写完3/4,那些熬夜赶作业的日子仍然历历在目,仿佛是昨 ...
- 动态规划-LCS最长公共子序列
#include<iostream> #include<cstdio> #include<cstring> #include<string> using ...
- mysql有多大内存?能存多少数据?
Mysql: MySQL 3.22 限制的表大小为4GB. MyISAM 存储引擎: 最大表尺寸增加到了65536TB(2567 – 1字节).由于允许的表尺寸更大,MySQL数据库的最大有效表尺寸通 ...
- js tool 方法之删除数组指定项
最近又开始写博文了,还是在自己的本地项目上做一些小的方法案例. 之前撸代码的时候总是遇到删除数组里某个元素的问题,JS没提供便捷的方法,只能自己写个循环处理,所幸自己写个方法,以后博客项目里要用到就不 ...
- fun = [lambda x: x*i for i in range(4)] 本质解析/原理,LEGB规则 闭包原理
命名空间,闭包原理,参考点击本文 一.问题描述 fun = [lambda x: x*i for i in range(4)] for item in fun: print(item(1)) 上述式子 ...
- CRM系统(第四部分)
阅读目录 1.引入权限组件rbac 2.分配权限 3.登录.引入中间件 1.引入权限组件rbac 1.settings配置app.中间件 INSTALLED_APPS = [ ... ... ...
- 弹性(flex)布局
五大主流浏览器及其内核:谷歌浏览器:Google Chrome.内核是blink火狐浏览器:Mozilla Firefox.内核是Gecko:欧鹏浏览器:OPera.内核是blink苹果浏览器:Saf ...
- [转帖]利用hydra(九头蛇)暴力破解内网windows登录密码
利用hydra(九头蛇)暴力破解内网windows登录密码 https://blog.csdn.net/weixin_37361758/article/details/77939070 尝试了下 能够 ...
- Git SSH公钥配置
https://www.cnblogs.com/smuxiaolei/p/7484678.html https://blog.csdn.net/weixin_42063071/article/deta ...