POJ训练计划2528_Mayor's posters(线段树/成段更新+离散化)
解题报告
题意:
一些海报,覆盖上去后还能看到几张。
思路:
第一道离散化的题。
离散化的意思就是区间压缩然后映射。
给你这么几个区间[1,300000],[3,5],[6,10],[4,9]
区间左右坐标排序完就是
1,3,4,5,6,9,10,300000;
1,2,3,4,5,6, 7 ,8;
我们能够把上面的区间映射成[1,8],[2,4],[5,7],[3,6];
这样就节省了非常多空间。
给线段染色, lz标记颜色。
#include <map>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
struct node
{
int x,y;
} p[10100];
int zb[20100],_hash[10100],lz[100000],ans;
void push_down(int root )
{
if(lz[root])
{
lz[root*2]=lz[root*2+1]=lz[root];
lz[root]=0;
}
}
void update(int root,int l,int r,int ql,int qr,int v)
{
if(ql>r||qr<l)return;
if(ql<=l&&r<=qr)
{
lz[root]=v;
return;
}
push_down(root);
int mid=(l+r)/2;
update(root*2,l,mid,ql,qr,v);
update(root*2+1,mid+1,r,ql,qr,v);
}
void _q(int root,int l,int r)
{
if(lz[root])
{
if(!_hash[lz[root]])
ans++;
_hash[lz[root]]=1;
return ;
}
if(l==r)return;
int mid=(l+r)/2;
_q(root*2,l,mid);
_q(root*2+1,mid+1,r);
}
int main()
{
int t,i,j,n;
scanf("%d",&t);
while(t--)
{
ans=0;
memset(_hash,0,sizeof(_hash));
scanf("%d",&n);
for(i=0; i<n; i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
zb[i]=p[i].x;
zb[i+n]=p[i].y;
}
sort(zb,zb+n*2);
int m=unique(zb,zb+n*2)-zb;
for(i=0; i<n; i++)
{
int ql=lower_bound(zb,zb+m,p[i].x)-zb+1;
int qr=lower_bound(zb,zb+m,p[i].y)-zb+1;
update(1,1,m,ql,qr,i+1);
}
_q(1,1,m);
printf("%d\n",ans);
}
}
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 41877 | Accepted: 12199 |
Description
and introduce the following rules:
- Every candidate can place exactly one poster on the wall.
- All posters are of the same height equal to the height of the wall; the width of a poster can be any integer number of bytes (byte is the unit of length in Bytetown).
- The wall is divided into segments and the width of each segment is one byte.
- Each poster must completely cover a contiguous number of wall segments.
They have built a wall 10000000 bytes long (such that there is enough place for all candidates). When the electoral campaign was restarted, the candidates were placing their posters on the wall and their posters differed widely in width. Moreover, the candidates
started placing their posters on wall segments already occupied by other posters. Everyone in Bytetown was curious whose posters will be visible (entirely or in part) on the last day before elections.
Your task is to find the number of visible posters when all the posters are placed given the information about posters' size, their place and order of placement on the electoral wall.
Input
the n lines contains two integer numbers li and ri which are the number of the wall segment occupied by the left end and the right end of the i-th poster, respectively. We know that for each 1 <= i <= n, 1 <= li <= ri <= 10000000. After
the i-th poster is placed, it entirely covers all wall segments numbered li, li+1 ,... , ri.
Output
The picture below illustrates the case of the sample input.

Sample Input
1
5
1 4
2 6
8 10
3 4
7 10
Sample Output
4
POJ训练计划2528_Mayor's posters(线段树/成段更新+离散化)的更多相关文章
- POJ 2777 Count Color (线段树成段更新+二进制思维)
题目链接:http://poj.org/problem?id=2777 题意是有L个单位长的画板,T种颜色,O个操作.画板初始化为颜色1.操作C讲l到r单位之间的颜色变为c,操作P查询l到r单位之间的 ...
- poj 3468 A Simple Problem with Integers 【线段树-成段更新】
题目:id=3468" target="_blank">poj 3468 A Simple Problem with Integers 题意:给出n个数.两种操作 ...
- 线段树(成段更新) POJ 3468 A Simple Problem with Integers
题目传送门 /* 线段树-成段更新:裸题,成段增减,区间求和 注意:开long long:) */ #include <cstdio> #include <iostream> ...
- poj 3648 线段树成段更新
线段树成段更新需要用到延迟标记(或者说懒惰标记),简单来说就是每次更新的时候不要更新到底,用延迟标记使得更新延迟到下次需要更新or询问到的时候.延迟标记的意思是:这个区间的左右儿子都需要被更新,但是当 ...
- ACM: Copying Data 线段树-成段更新-解题报告
Copying Data Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description W ...
- Codeforces Round #149 (Div. 2) E. XOR on Segment (线段树成段更新+二进制)
题目链接:http://codeforces.com/problemset/problem/242/E 给你n个数,m个操作,操作1是查询l到r之间的和,操作2是将l到r之间的每个数xor与x. 这题 ...
- hdu 4747【线段树-成段更新】.cpp
题意: 给出一个有n个数的数列,并定义mex(l, r)表示数列中第l个元素到第r个元素中第一个没有出现的最小非负整数. 求出这个数列中所有mex的值. 思路: 可以看出对于一个数列,mex(r, r ...
- HDU1698_Just a Hook(线段树/成段更新)
解题报告 题意: 原本区间1到n都是1,区间成段改变成一个值,求最后区间1到n的和. 思路: 线段树成段更新,区间去和. #include <iostream> #include < ...
- HDU 3577 Fast Arrangement ( 线段树 成段更新 区间最值 区间最大覆盖次数 )
线段树成段更新+区间最值. 注意某人的乘车区间是[a, b-1],因为他在b站就下车了. #include <cstdio> #include <cstring> #inclu ...
随机推荐
- Wireshark、Netcat
Wireshark Wireshark是一个网络数据包分析软件,功能是截取网络数据包,并尽可能显示出最为详细的网络数据包数据.为了安全考虑,wireshark只能查看封包,而不能修改封包的内容,或者发 ...
- 洛谷P3964 [TJOI2013]松鼠聚会 [二分答案,前缀和,切比雪夫距离]
题目传送门 松鼠聚会 题目描述 草原上住着一群小松鼠,每个小松鼠都有一个家.时间长了,大家觉得应该聚一聚.但是草原非常大,松鼠们都很头疼应该在谁家聚会才最合理. 每个小松鼠的家可以用一个点x,y表示, ...
- Lighthouse前端性能优化测试工具
在前端开发中,对于自己开发的app或者web page性能的好坏,一直是让前端开发很在意的话题.我们需要专业的网站测试工具,让我们知道自己的网页还有哪些需要更为优化的方面,我自己尝试了一款工具:Lig ...
- Spring-Session实现Session共享Redis集群方式配置教程
循序渐进,由易到难,这样才更有乐趣! 概述 本篇开始继续上一篇的内容基础上进行,本篇主要介绍Spring-Session实现配置使用Redis集群,会有两种配置方式,一种是Redis-Cluster, ...
- 命令:install
简介 从命令的名字上来看,会让人误以为这是一个和安装相关的命令. 其实不然,install命令用于复制文件(cp)或创建空目录(mkdir)并设置相关的属性(chown.chmod). 这里的属性包含 ...
- ubuntu下安装flash player,浏览器观看视频,本人ubuntu版本14.04
首先去官网下载flash player安装包:flash_player_npapi_linux.x86_64,下载地址:https://get.adobe.com/cn/flashplayer/ 解压 ...
- POJ1274 The Perfect Stall[二分图最大匹配 Hungary]【学习笔记】
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23911 Accepted: 106 ...
- BZOJ 4198: [Noi2015]荷马史诗 哈夫曼树 k叉哈夫曼树
https://www.lydsy.com/JudgeOnline/problem.php?id=4198 https://blog.csdn.net/chn_jz/article/details/7 ...
- NOIP练习赛题目1
有些题目可能没做,如计算几何.恶心模拟. 高级打字机 难度级别:C: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 早苗入手了最新的高级打字机 ...
- BZOJ2217 : [Poi2011]Lollipop
若能得到一个和为t的区间,那么至少去掉两端点中任意一个后必定能得到和为t-2的区间. 所以只需要分别找到和最大的和为奇数和偶数的区间,然后$O(n)$完成构造即可. #include<cstdi ...