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 ...
随机推荐
- Thinkphp模板标签if和eq的区别和比较
在TP模板语言中.if和eq都可以用于变量的比较.总结以下几点: 1.两个变量的比较: <if condition=”$item.group_id eq $one.group_id”> & ...
- 解决phpmyadmin数据文件导入有限制的问题(只能导入2M以下)
修改配置php.ini文件中三个参数: 1.upload_max_filesize 2.memory_limit 3.post_max_size 建议根据实际需要进行设置.
- ECMA里面的一元符
只能操作一个值的叫做一元操作符.一元操作符是ECMAScript中最简单的操作符 1.递增和递减操作符 递增和递减操作符直接借鉴自c,而且各有俩个版本,前置型和后置型.顾名思义,前置型就是位于要操作的 ...
- LoadRunner监控Linux配置教程
LoadRunner监控Linux资源时弹出如下错误: Monitor name :UNIX Resources. Cannot initialize the monitoring on 192.16 ...
- php使用邮箱发送验证码
如果看着文字眼乏就去看看视频吧-> 如何注册腾讯企业邮箱 https://www.bilibili.com/video/av14351397/ 如何在项目中使用 https://www.bili ...
- ACM_N皇后问题
N皇后问题 Time Limit: 2000/1000ms (Java/Others) Problem Description: 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不 ...
- 记录sql操作
需求:一个a表的A列等于b表的B列 但拥有的相同列C列值不相同 需要将其改成一样的 UPDATE vd_auth_switch vas,tb_student ts set vas.class_id = ...
- 全面学习ORACLE Scheduler特性(7)Scheduler抛出的Events
四.使用Events Event直译对应的中文解释是指事件,不过单纯讲事件毕竟太抽象了,举个示例来形容吧.A(对应某个应用程序,或者是ORACLE中的进程)在干活时突然眉头一皱说道,不好,前方有情况, ...
- 四种IO模型
四种 IO 模型: 首先需要明确,IO发生在 用户进程 与 操作系统 之间.可以是客户端IO也可以是服务器端IO. 阻塞IO(blocking IO): 在linux中,默认情况下 ...
- 372 Super Pow 超级次方
你的任务是计算 ab 对 1337 取模,a 是一个正整数,b 是一个非常大的正整数且会以数组形式给出.示例 1:a = 2b = [3]结果: 8示例 2:a = 2b = [1,0]结果: 102 ...