POJ 2528 Mayor's posters 贴海报 线段树 区间更新
注意离散化!!!线段树的叶子结点代表的是一段!!!
给出下面两个简单的例子应该能体现普通离散化的缺陷:
1-10 1-4 5-10
1-10 1-4 6-10
普通离散化算出来的结果都会是2,但是第二组样例结果是3
如果相邻数字间距大于1的话,在其中加上任意一个数字,比如加成[1,2,3,6,7,10],然后再做线段树就好了.
线段树功能:update 成段更新,query 查询整个线段树
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
using namespace std; const int MAXN = 20010;
int p[MAXN], mp[MAXN], pp[MAXN];
int pst[MAXN<<4], ans;
bool flag[MAXN]; bool cmp(int A, int B)
{
return p[A] < p[B];
} void push_down(int rt)
{
if(pst[rt] == 0) return;
pst[rt<<1] = pst[rt<<1|1] = pst[rt];
pst[rt] = 0;
} void update(int L, int R, int c, int l, int r, int rt)
{
if(L <= l && r <= R)
{
pst[rt] = c;
return;
}
push_down(rt);
int m = (l + r) >> 1;
if(m >= L) update(L, R, c, lson);
if(m < R) update(L, R, c, rson);
} void query(int l, int r, int rt)
{
if(pst[rt] > 0) //只有大于0才有海报
{
if(!flag[pst[rt]]) ans++;
flag[pst[rt]] = 1;
return;
}
if(l == r) return;
push_down(rt);
int m = (l + r) >> 1;
query(lson);
query(rson);
} int main()
{
// freopen("in.txt", "r", stdin);
int T, n;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
for(int i=0; i<n; i++)
{
scanf("%d%d", &p[i<<1], &p[i<<1|1]);
mp[i<<1] = i<<1;
mp[i<<1|1] = i<<1|1;
}
sort(mp, mp+2*n, cmp);
pp[mp[0]] = 1;
int N = 1;
for(int i=1; i<2*n; i++) //离散化
{
if(p[mp[i]] == p[mp[i-1]])
pp[mp[i]] = N;
else if(p[mp[i]] - p[mp[i-1]] > 1) //大于1的插一个数
{
N += 2;
pp[mp[i]] = N;
}
else pp[mp[i]] = ++N;
}
memset(pst, 0, sizeof(pst));
for(int i=0; i<n; i++)
update(pp[i<<1], pp[i<<1|1], i+1, 1, N, 1);
memset(flag, 0, sizeof(flag));
ans = 0;
query(1, N, 1);
printf("%d\n", ans);
}
return 0;
}
POJ 2528 Mayor's posters 贴海报 线段树 区间更新的更多相关文章
- POJ - 2528 Mayor's posters (离散化+线段树区间修改)
https://cn.vjudge.net/problem/POJ-2528 题意 给定一些海报,可能相互重叠,告诉你每个海报的宽度(高度都一样的)和先后叠放顺序,问没有被完全盖住的有多少张? 分析 ...
- poj 3468 A Simple Problem with Integers (线段树区间更新求和lazy思想)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 75541 ...
- HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5023 解题报告:一面墙长度为n,有N个单元,每个单元编号从1到n,墙的初始的颜色是2,一共有30种颜色 ...
- (简单) 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 ...
- [POJ] 3468 A Simple Problem with Integers [线段树区间更新求和]
A Simple Problem with Integers Description You have N integers, A1, A2, ... , AN. You need to deal ...
- A Corrupt Mayor's Performance Art(线段树区间更新+位运算,颜色段种类)
A Corrupt Mayor's Performance Art Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 100000/100 ...
- POJ 3468 A Simple Problem with Integers(线段树区间更新)
题目地址:POJ 3468 打了个篮球回来果然神经有点冲动. . 无脑的狂交了8次WA..竟然是更新的时候把r-l写成了l-r... 这题就是区间更新裸题. 区间更新就是加一个lazy标记,延迟标记, ...
- POJ 3468 A Simple Problem with Integers(线段树区间更新,模板题,求区间和)
#include <iostream> #include <stdio.h> #include <string.h> #define lson rt<< ...
- POJ 3468 A Simple Problem with Integers 线段树 区间更新
#include<iostream> #include<string> #include<algorithm> #include<cstdlib> #i ...
随机推荐
- ocalhost kernel: [244840.301449] nf_conntrack: nf_conntrack: table full, dropping packet
nf_conntrack: table full, dropping packet. 终结篇 "连接跟踪表已满,开始丢包"!相信不少用iptables的同学都会见过这个错误信息 ...
- centos国内镜像下载
国内镜像下载 http://mirrors.aliyun.com/centos/6/isos/x86_64/ 如果需要下载centos 7 版本进入对应7的/isos/x86_64/ 选择minima ...
- Linux 根目录所在分区被脏数据占满
背景: 公司在做一个项目,大概功能就是一个通行闸机的人脸识别系统,要经过门禁的人注册了之后,系统就会存储一张原始的图片在服务器的数据文件夹里面,包括了永久的存储和一些访客注册临时存储.一天周五的时 ...
- 联想 lenove 3750 M4服务器更改启动项和管理口IP
联想 lenove 3750 M4服务器更改启动项和管理口IP 注: 因为在机房拍照的原因,再加上工作比较忙:整理成文档的时候有的过程已经忘记了,所以有的步骤可能会缺失,里面的选项都已经用中文方式表达 ...
- Mysql体系结构管理
1.客户端与服务端模型 1)数据是一个典型的C/S结构的服务 1.mysql自带的客户端工具 mysql mysqladmin mysqldump 3.mysql是一个二进制程序,后台守护进程 单进程 ...
- 003.kubernets对于namespace的管理
一 Kuberbetes的架构简单介绍 1.1 云计算的传统分类 1.2 kubernetes基础架构 工作机制 用户通过kubectl向api-server提交需要运行的pod描述 api-serv ...
- 学完了这篇JVM,面试官真拿我没办法了!
在我们面试中经常会遇到面试官问一些有关JVM的问题,下面我大概从运行时数据域.类加载机制.类加载器.垃圾收集器.垃圾收集算法.JVM堆内存模型.JVM内存结构.JVM调优等几个方面来讲一下JVM. 一 ...
- 【MybatisPlus】数据库的datetime类型字段为空的时候,报错空指针?
一.发现经历 事情是这样的,我今天本来要演示系统,就去前端同学的页面上点一点.不小心点到了其他同事编写的服务,然后界面就报错了.这给我吓得,这还能演示吗这.然后,我就去服务器查看了一下日志,发现了如下 ...
- 针对Spring MVC的Interceptor内存马
针对Spring MVC的Interceptor内存马 目录 针对Spring MVC的Interceptor内存马 1 基础拦截器和调用流程的探索 1.1 基础拦截器 1.2 探索拦截器的调用链 1 ...
- 北汽极狐ARCFOX与华为合作
北汽极狐ARCFOX与华为合作 全球首款激光雷达量产车 2021年,是激光雷达"上车"的元年. 曾经价格高不可攀,只能用于Robotaxi.无人车测试的激光雷达,终于彻底具备商业化 ...