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 ...
随机推荐
- map的遍历方式(使用Junit测试)
package cn.sdut.lah; import java.util.HashMap; import java.util.Iterator; import java.util.Map; impo ...
- PHP的包依赖管理工具Composer简介
composer是一个基于项目的依赖管理器,负责将php项目的所依赖的包和库安装在项目的目录中,默认不会不会安装任何数据到全局.他用于取代之前pear工具 1 安装Composer curl -sS ...
- [BZOJ3224/Tyvj1728]普通平衡树
本篇博客有详细题解,浅谈算法--splay
- ACM_三角形的周长
三角形的周长 Time Limit: 2000/1000ms (Java/Others) Problem Description: 有n根棍子,棍子i的长度为ai,想要从中选出3根棍子组成周长尽可能长 ...
- 409 Longest Palindrome 最长回文串
给定一个包含大写字母和小写字母的字符串,找到通过这些字母构造成的最长的回文串.在构造过程中,请注意区分大小写.比如 "Aa" 不能当做一个回文字符串.注意:假设字符串的长度不会超过 ...
- 235 Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最近公共祖先
给定一棵二叉搜索树, 找到该树中两个指定节点的最近公共祖先. 详见:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-s ...
- C语言学习(1)-环境配置
写在前面的话,该文章是看杨老师的一套视频,所做的一些笔记,边看边写,再此谢谢杨老师. 1.学习C之前需要避免的误区 误区一:C++是C的升级版:C#是C++的升级版 误区二:C/C++就是Visual ...
- poj1778 All Discs Considered
思路: 拓扑排序.贪心. 实现: #include <bits/stdc++.h> using namespace std; vector<]; int n1, n2; inline ...
- 微信小程序资料总结
http://blog.csdn.net/ZCLengendary/article/details/54312030 --添加html标签与处理 https://www.cnblogs.com/HD ...
- 关于ds添加datarow
有一个dataset DS.如果我想将DS中的某一行复制,得到新的一行,添加到DS中. 可能就会想到:DS.Tables[0].Rows.Add(DS.Tables[0].Rows[i])但是这样程序 ...