POJ2528 Uva10587 Mayor's posters
- 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. //图片粘不上来,一直转圈圈,uva链接,洛谷链接

Sample Input
1
5
1 4
2 6
8 10
3 4
7 10
Sample Output
4
解题思路
1
3
1 6
1 3
5 6
源代码
#include<stdio.h>
#include<algorithm> int n,T; int post[][]/*海报位置*/,input[]/*需要离散化的数*/; struct Segtree{
int l,r;
int c;//如果区间长度为1,则记录海报编号,否则随缘(记录的啥我不管)(这里好像可以再优化一下,把c弄出去,搞成一个长度1e5的数组)
}s[];//从1号开始
int lazy[];
inline int lson(int a){return a<<;}
inline int rson(int a){return (a<<)|;}
void maketree(int x,int l,int r)
{
lazy[x]=;
if(l==r)
{
s[x]={l,r,};
return;
}
s[x].l=l;
s[x].r=r;
int mid=l+r>>;
maketree(lson(x),l,mid);
maketree(rson(x),mid+,r);
s[x].c=;
}
inline void pushdown(int x)
{
if(!lazy[x]) return;
int ls=lson(x),rs=rson(x);
s[ls].c=lazy[x];
lazy[ls]=lazy[x];
s[rs].c=lazy[x];
lazy[rs]=lazy[x];
lazy[x]=;
}
int quepos(int x,int pos)
{
int mid=s[x].l+s[x].r>>;
if(s[x].l==s[x].r) return s[x].c;
if(lazy[x]) return lazy[x];
if(pos<=mid) return quepos(lson(x),pos);
else return quepos(rson(x),pos);
}
void update(int x,int l,int r,int k)
{
if(l>s[x].r||r<s[x].l) return;
if(l<=s[x].l&&s[x].r<=r)
{
// s[x].sum+=k*(s[x].r-s[x].l+1);
if(s[x].l==s[x].r) s[x].c=k;
else lazy[x]=k;
return;
}
pushdown(x);
update(lson(x),l,r,k);
update(rson(x),l,r,k);
} int main()
{
//freopen("test.in","r",stdin);//因为忘记注释这个,WA了不知多少
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
int len=;//离散化数组input的长度
for(int i=;i<=n;i++)
{
scanf("%d%d",&post[i][],&post[i][]);
input[len++]=post[i][];
input[len++]=post[i][];
input[len++]=post[i][]+;
} std::sort(input,input+len+);
len=std::unique(input,input+len+)-input;
for(int i=;i<=n;i++)
{
post[i][]=std::lower_bound(input,input+len,post[i][])-input;
post[i][]=std::lower_bound(input,input+len,post[i][])-input;
} maketree(,,len);
for(int i=;i<=n;i++)
update(,post[i][],post[i][],i);//海报编号1~n
int *count;
count=new int[n]();
for(int i=;i<=len;i++)
count[quepos(,i)]=; int ans=;
for(int i=;i<=n;i++) ans+=count[i];
delete count;
printf("%d\n",ans);
}
return ;
}
POJ2528 Uva10587 Mayor's posters的更多相关文章
- 【poj2528】Mayor's posters
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 64939 Accepted: 18770 ...
- 【SDOJ 3741】 【poj2528】 Mayor's posters
Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...
- 【poj2528】Mayor's posters
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 59254 Accepted: 17167 Description The ...
- 线段树---poj2528 Mayor’s posters【成段替换|离散化】
poj2528 Mayor's posters 题意:在墙上贴海报,海报可以互相覆盖,问最后可以看见几张海报 思路:这题数据范围很大,直接搞超时+超内存,需要离散化: 离散化简单的来说就是只取我们需要 ...
- Mayor's posters(线段树+离散化POJ2528)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 51175 Accepted: 14820 Des ...
- poj2528 Mayor's posters(线段树之成段更新)
Mayor's posters Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 37346Accepted: 10864 Descr ...
- poj-----(2528)Mayor's posters(线段树区间更新及区间统计+离散化)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 43507 Accepted: 12693 ...
- poj2528 Mayor's posters(线段树区间覆盖)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 50888 Accepted: 14737 ...
- [POJ2528]Mayor's posters(离散化+线段树)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 70365 Accepted: 20306 ...
随机推荐
- mysql 的索引hash和b+tree 区别
索引hash相当于数组,键值对组合,对于id = 6或者status= 2这样条件查询,但是对于id>12等这样,用btree索引最好.
- 【计蒜客习题】 取石子游戏(gcd)
问题描述 蒜头君和花椰妹在玩一个游戏,他们在地上将 n 颗石子排成一排,编号为 1 到 n.开始时,蒜头君随机取出了 2 颗石子扔掉,假设蒜头君取出的 2 颗石子的编号为 a, b.游戏规则如下,蒜头 ...
- 生成自签名ca 证书 使nginx 支持https
创建服务器私钥,命令会让你输入一个口令:$ openssl genrsa -des3 -out server.key 1024创建签名请求的证书(CSR):$ openssl req -new -ke ...
- 一个包含所有C++头文件的头函数
#include<bits/stdc++.h> using namespace std; 使用方法和平常的头文件一样,#include<bits/stdc++.h>包含以下头文 ...
- Spring加载applicationContext.xml实现spring容器管理的几种方式
package com.etc.test; import org.junit.Test; import org.springframework.beans.factory.BeanFactory; i ...
- 全面学习ORACLE Scheduler特性(9)创建Chains
五.使用Chains 今天要来认识一位新同学:CHAIN(注意不要敲成CHINA).CHAIN可以被视做一组Programs的复合,举个简单的例子:运行PROGRAM:A以及PROGRAM:B,如果成 ...
- 基于Web的Kafka管理器工具之Kafka-manager的编译部署详细安装 (支持kafka0.8、0.9和0.10以后版本)(图文详解)(默认端口或任意自定义端口)
不多说,直接上干货! 至于为什么,要写这篇博客以及安装Kafka-manager? 问题详情 无奈于,在kafka里没有一个较好自带的web ui.启动后无法观看,并且不友好.所以,需安装一个第三方的 ...
- Spark学习笔记1:Application,Driver,Job,Task,Stage理解
看了spark的原始论文和相关资料,对spark中的一些经常用到的术语做了一些梳理,记录下. 1,Application application(应用)其实就是用spark-submit提交的程序.比 ...
- C语言指针的理解以及指针的指针的理解
指针指向的是内存地址编号,内存地址编号指向的是对应的内容. 我们需要一个变量,来储存内存地址编号,这个变量的值是一个内存地址编号,但是我们可以通过修改变量的值,来不断的改变内存地址编号. 但是,我们如 ...
- Asp.net MVC中文件上传的参数转对象的方法
参照博友的.NET WebApi上传文件接口(带其他参数)实现文件上传并带参数,当需要多个参数时,不想每次都通过HttpContext.Request.Params去取值,就针对HttpRequest ...