【SDOJ 3741】 【poj2528】 Mayor's posters
Description
- 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
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 太令人窒息了!!!!!查错两小时!!!!!
很容易看得出来这是个线段树,每次贴一张就相当于一次区间修改,完了之后刷一遍看有多少种.....
but....
仅仅这样是不够的,数据范围疯狂暗示我们它想要离散化
然后就完了
一定要注意不要写错板子啊啊啊啊啊啊啊
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define N 200010
#define lc p<<1
#define rc p<<1|1
using namespace std;
int n,t,m,tot;
int ll[N],rr[N],a[N],col[N],ans;
bool vis[N];
struct tree
{
int l,r;
int lazy,c;
}T[N*];
inline void pushnow(int p,int c)
{
T[p].lazy=c;
T[p].c=c;
}
inline void pushup(int p)//√
{
if(!T[lc].c||!T[rc].c||T[lc].c!=T[rc].c) T[p].c=;
else T[p].c=T[rc].c;
}
inline void pushdown(int p)
{
if(T[p].lazy!=-)
{
pushnow(lc,T[p].lazy);
pushnow(rc,T[p].lazy);
T[p].lazy=-;
}
}
void build(int p,int l,int r)//√
{
T[p].l=l; T[p].r=r;
if(l==r)
{
T[p].c=-;
T[p].lazy=-;
return;
}
int mid=(T[p].l+T[p].r)>>;
build(lc,l,mid); build(rc,mid+,r);
pushup(p);
}
void update(int p,int ql,int qr,int v)
{
if(ql<=T[p].l&&T[p].r<=qr)//!!!!!!!!!!!!!!!!!!
{
pushnow(p,v);
return;
}
pushdown(p);
int mid=(T[p].l+T[p].r)>>;
if(ql<=mid) update(lc,ql,qr,v);
if(qr>mid) update(rc,ql,qr,v);
pushup(p);
} void query(int p,int ql,int qr)
{
if(T[p].c==-) return;
else if(T[p].c>)
{
col[T[p].c]=;
return;
}
int mid=(T[p].l+T[p].r)>>;
pushdown(p);
if(ql<=mid) query(lc,ql,qr);
if(qr>mid) query(rc,ql,qr);
}
int main()
{
scanf("%d",&t);
while(t--)
{
int ans=;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
int pl,pr;
scanf("%d%d",&pl,&pr);
ll[i]=pl; rr[i]=pr;
a[i*-]=pl;a[i*]=pr;
}
sort(a+,a++*n);
m=unique(a+,a++*n)-(a+);
tot=m;
for(int i=;i<m;i++)
if(a[i]+<a[i+])
a[++tot]=a[i]+;
sort(a+,a++tot);
build(,,tot);
memset(col,,sizeof(col));
for(int i=;i<=n;i++)
{
int x=lower_bound(a+,a++tot,ll[i])-a;
int y=lower_bound(a+,a++tot,rr[i])-a;
//cout<<x<<" "<<y<<endl;
update(,x,y,i);
}
query(,,tot);
for(int i=;i<=n;i++)
if(col[i]) ans++;
printf("%d\n",ans);
}
return ;
}
这是一篇代码
【SDOJ 3741】 【poj2528】 Mayor's posters的更多相关文章
- POJ2528 Uva10587 Mayor's posters
The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...
- 线段树---poj2528 Mayor’s posters【成段替换|离散化】
poj2528 Mayor's posters 题意:在墙上贴海报,海报可以互相覆盖,问最后可以看见几张海报 思路:这题数据范围很大,直接搞超时+超内存,需要离散化: 离散化简单的来说就是只取我们需要 ...
- POJ2528 Mayor's posters 【线段树】+【成段更新】+【离散化】
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39795 Accepted: 11552 ...
- 【poj2528】Mayor's posters
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 64939 Accepted: 18770 ...
- 【线段树】Mayor's posters
[poj2528]Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 66154 Accept ...
- 【POJ】2528 Mayor's posters ——离散化+线段树
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Description The citizens of Bytetown, A ...
- POJ 2528——Mayor's posters——————【线段树区间替换、找存在的不同区间】
Mayor's posters Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- POJ 2528 Mayor's posters 【区间离散化+线段树区间更新&&查询变形】
任意门:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total S ...
- 【英语魔法俱乐部——读书笔记】 3 高级句型-简化从句&倒装句(Reduced Clauses、Inverted Sentences) 【完结】
[英语魔法俱乐部——读书笔记] 3 高级句型-简化从句&倒装句(Reduced Clauses.Inverted Sentences):(3.1)从属从句简化的通则.(3.2)形容词从句简化. ...
随机推荐
- IOSruntime : 运行时机制
首先必须明白的: 1.是什么 1> runtime是一套比较底层的纯C语言API, 属于1个C语言库, 包含了很多底层的C语言API 2> 平时编写的OC代码, 在程序运行过程中, 其实最 ...
- Winform中Checkbox与其他集合列表类型之间进行关联
本文提供了Checkbox与CheckedListBox.DataGridViewCheckBoxColumn等的联动关系 1.CheckboxAssociateFactroy.Create创建联动关 ...
- 通过CMD命令行创建和使用Android 模拟器 AVD
进行Android APP测试时,若手持android手机设备稀少的情况下,我们可以通过创建Android模拟器AVD来代替模拟android手机设备,本文就具体介绍如何创建和使用AVD. 1.创建A ...
- 【Python图像特征的音乐序列生成】第一阶段的任务分配
从即日起到7月20号,项目成员进行了第一次任务分配. 赵同学A.岳同学.周同学,负责了图像数据的情感数据集制作,他们根据自己的经验,对图像进行了情绪提取. 赵同学B全权负责向量映射这一块的网络搭建. ...
- 问题驱动的Git学习
(搬运自我在SegmentFault的博客) 本人是个Git新手,平时用Git最多的就是push,因为别的都不怎么会用.这几天因为在小组中负责代码的整合,顺便将代码提交到Github,接触到了Git更 ...
- codeforce Gym 100342H Hard Test (思考题)
题意:构造让Dijkstra单源最短路算法有效松弛次数最多的数据... 题解:构造,题意换种说法就是更新晚的路径要比更新早的路径短.因为所有点都会更新一次,那么按照更新时间形成一条链,即到最后一个点的 ...
- Tarjan的学习笔记 求割边求割点
博主图论比较弱,搜了模版也不会用... 所以决心学习下tarjan算法. 割点和割边的概念不在赘述,tarjan能在线性时间复杂度内求出割边. 重要的概念:时间戟,就是一个全局变量clock记录访问结 ...
- spring maven 包
<spring-framework.version>.RELEASE</spring-framework.version> <dependency> <gro ...
- (六)VMware Harbor简单使用
VMware Harbor简单使用 1. 登陆: [用户:admin , 密码:Harbor12345]配置文件里设置的 登陆后的界面: 2. 用户管理: 2.1 新近用户 3. 仓库管理: 3.1 ...
- String中关于BeanFactory
org.springframework.beans及org.springframework.context包是Spring IoC容器的基础.BeanFactory提供的高级配置机制,使得管理任何性质 ...