【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)形容词从句简化. ...
随机推荐
- 零基础逆向工程15_C语言09_位运算
1.汇编中的移位指令 算数移位指令 指令格式:SAL/SAR Reg/Mem, CL/Imm SAL(Shift Arithmetic Left):算数左移 SAR(Shift Arithmetic ...
- Elasticsearch-基本操作2
Elasticsearch版本:6.0 为了避免并发修改的冲突问题,数据库中,经常用悲观锁和乐观锁来控制并发问题,而Elasticsearch使用乐观锁.如果源数据在读写过程中被修改,更新将失败,应用 ...
- iOS Programming Autorotation, Popover Controllers, and Modal View Controllers
iOS Programming Autorotation, Popover Controllers, and Modal View Controllers 自动旋转,Popover 控制器,Moda ...
- Azure 门户使用概览
Azure 门户是管理 Azure 云平台的核心工具,用户可以在其中预配和管理 Azure 资源.本教程将帮助你熟悉Azure管理门户,包括一些关键功能的介绍,并演示了如何通过 Azure 门户创建虚 ...
- python基础教程总结8——特殊方法,属性,迭代器,生成器,八皇后问题
1. 重写一般方法和特殊的构造方法 1.1 如果一个方法在B类的一个实例中被调用(或一个属性被访问),但在B类中没有找到该方法,那么会去它的超类A里面找. class A: ... def hello ...
- CF Gym 100187A Potion of Immortality (思路,最坏情况的最小损失)
根据兔子试药情况可以缩小范围,如果死了,不在试过的药里面,如果活着,在试过的药里. 最糟的情况: 两个原则 1.能确定魔药所在的范围的尽量大,2.死得兔子尽量多. 如果当前不知道情况的药n为k的二倍以 ...
- Android(java)学习笔记133:Eclipse中的控制台不停报错Can't bind to local 8700 for debugger
[DDMS] Can't bind to local 8600 for debugger 改成 Under Window -> Preferences -> Android -> D ...
- Netbackup8.0以上版本,服务端生成证书,客户端获取、更新证书方式(整理中)
创建重发令牌 如果非主控主机已在主服务器上注册但其基于主机ID的证书不再有效,则可以重新颁发基于主机ID的证书.例如,证书在过期,被撤销或丢失时无效. 重发令牌是一种可用于重新颁发证书的令牌.它是一种 ...
- Array - Remove Element
/** * 无额外空间.顺序可以被改变.不需要修改后面的数字. * @param nums 数组 * @param val 目标值 * @return nums中移除val后的长度 */ public ...
- 剑指offer24 二叉搜索树的后序遍历序列
自己写的更简洁的代码 class Solution { public: bool VerifySquenceOfBST(vector<int> sequence) { int length ...