Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [题目类型]线段树+离散化 &题意: 给出一面墙,给出n张海报贴在墙上,每张海报都覆盖一个范围,问最后可以看到多少张海报 &题解: 海报覆盖的范围很大,直接使用数组存不下,但是只有最多10000张海报,也就是说最多出现20000个点,所以可以使用离散化,将每个点离散后,重新对给出控制的区间,这样…
Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an ele…
线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an electoral…
poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) 假设给出: 1~10 1~4 7-10 最后可以看见三张海报 如果离散化的时候不注意,就会变成 1 4 7 10(原始) 1 2 3 4 (离散化) 转化为: 1~4 1~2 3~4 这样的话最后只能看见两张海报 解决办法,如果原数据去重排序后相互之间差值大于1,则在他们之间再插入一个数值,使得大…
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 51175 Accepted: 14820 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters…
Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an ele…
Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:75394   Accepted: 21747 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral poste…
题目链接:http://poj.org/problem?id=2528 题目: 题意:将n个区间进行染色(对于同一个区间,后一次染色会覆盖上一次的染色),问最后可见的颜色有多少种. 思路:由于区间长度太大,而n就1e4,假设每次要染色的区间端点值都不相同也就2n,所以我们可以将区间进行离散化,然后对区间进行建树(不是对1,n建树).我们在节点结构体内部用mx来记录最后这个节点的颜色,flag来标记这个区间内部的颜色是否完全一样,对于一个节点的flag的更新方法为判断它的左右子节点的flag是否都…
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报左右坐标范围不超过10000000. 一看见10000000肯定就要离散化了,因为建树肯定是建不下.离散化的方法是:先存到一个数组里面,然后sort,之后unique去重,最后查他离散化的坐标lower_bound就行了.特别注意如果是从下标为0开始存储,最后结果要加一.多亏wmr神犇提醒. 这题是…
Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 43507   Accepted: 12693 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral post…
题目链接:https://vjudge.net/problem/POJ-2528 The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to…
绝对是很好的题 把问题转化成当第i个询问的答案是数值x时是否可行 要判断值x是否可行,只要再将问题转化成a数组里>=x的值数量是否严格大于b数组里的>=x的值 那么线段树叶子结点维护对于值x的a数组里的合法数数量-b数组里的合法数数量,如果是正数即这个值可行 线段树维护区间最大值,然后询问最靠右的非负叶子下标 #include<bits/stdc++.h> #include<vector> using namespace std; #define maxn 100000…
Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an electoral wall for…
Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an electoral wall for…
题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值.由于l和r范围比较大,内存就不够了,所以就用离散化的技巧 比如将1 4化为1 2,范围缩小,但是不影响答案. 写了这题之后对区间更新的理解有点加深了,重点在覆盖的理解(更新左右两个孩子节点,然后值清空),还是要多做做题目. #include <iostream> #include <cst…
Mayor's posters Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=2528 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at al…
Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 50888   Accepted: 14737 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral post…
题意 : 在墙上贴海报, n(n<=10000)个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=10000000).求出最后还能看见多少张海报. 分析 : 很容易想到利用线段树来成段置换,最后统计总区间不同数的个数.但是这里有一个问题,就是区间可以很大,线段树开不了那么大的空间,遂想能不能离散化.实际上只记录坐标的相对大小进行离散化最后是不影响我们计算的,但是光是普通的离散化是不行的,就是我们贴海报的实际意义是对(l, r)段进行添加,而不是对于这个区间的点…
Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 45703   Accepted: 13239 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral post…
Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 59683   Accepted: 17296 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral post…
The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an electoral wall for placing the…
Mayor's posters Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 37346Accepted: 10864 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at…
题目链接:http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=1610 题意:给一个长8000的绳子,向上染色.一共有n段被染色,问染色后共有多少不同的色段.注意假如相邻两个线段同色,那么算作一条线段. 线段树区间更新,不需要pushUP操作,因为查询和非叶节点无关.找长线段的时候首先定位最靠左那根,然后判后面是否与前面的线段颜色相等.注意有可能出现两条线段中间没有染色的情况,这时候查询返回一个无关值,这时候重置p即可. #inc…
题目:http://poj.org/problem?id=2528 题意:有一面墙,被等分为1QW份,一份的宽度为一个单位宽度.现在往墙上贴N张海报,每张海报的宽度是任意的, 但是必定是单位宽度的整数倍,且<=1QW.后贴的海报若与先贴的海报有交集,后贴的海报必定会全部或局部覆盖 先贴的海报.现在给出每张海报所贴的位置(左端位置和右端位置),问张贴完N张海报后,还能看见多少张海报? (离散化)+ 线段树 #include <iostream> #include <cstdio>…
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 40510 Accepted: 12215 Description Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems. Here, we get a new problem. The…
题目链接:https://ac.nowcoder.com/acm/contest/887/E 题意:给出L[i],R[i],每次添加L[i]...R[i],求出此时的中位数. 思路:因为添加的数范围为1e9,首先想到要用离散化,这里是用一个点来表示一个区间. 将右区间加一的主要目的是优化处理,将区间最后一个元素并入到前面,自己模拟一下就能明白啦. 然后用线段树维护每个节点所包含的元素个数,用懒惰标记laz表示加的次数,然后每次查询时若左子树的元素个数足够则在左子树查询,否则在右子树查询. 详见代…
给一块最大为10^8单位宽的墙面,贴poster,每个poster都会给出数据 a,b,表示该poster将从第a单位占据到b单位,新贴的poster会覆盖旧的,最多有10^4张poster,求最后贴完,会看到几张poster (哪怕只露出一个单位,也算该poster可见): 我一看这么大数据,又看了下时间限制只有1s,不科学啊,如果真的按10^8建树不可能过时间啊,而且根据它的空间限制,大概只能建10^7这么大的数组. 后来搜博客发现大家的标题都写着离散化,原来用离散化做这个题目,但是我不会离…
题意   在坐标系中有n条平行于y轴的线段  当一条线段与还有一条线段之间能够连一条平行与x轴的线不与其他线段相交  就视为它们是可见的  问有多少组三条线段两两相互可见 先把全部线段存下来  并按x坐标排序  线段树记录相应区间从右往左当前可见的线段编号(1...n)  超过一条就为0  然后从左往右对每条线段  先查询左边哪些线段和它是可见的  把可见关系存到数组中  然后把这条线段相应区间的最右端可见编号更新为这条线段的编号  最后暴力统计有多少组即可了 #include <cstdio>…
题目链接 题意 用不同颜色的线段覆盖数轴,问最终数轴上有多少种颜色? 注:只有最上面的线段能够被看到:即,如果有一条线段被其他的线段给完全覆盖住,则这个颜色是看不到的. 法一:线段树 按题意按顺序模拟即可. 法二:线段树+离线 将整个过程倒过来看待,如果要加进去的线段所在的区域已经完全被覆盖,那么这条线段就没有贡献,否则就有\(1\)的贡献. 法三:并查集+离线 离线处理思想同上. 用\(fa[\ ]\)数组记录某个元素左边距其最近的没有被覆盖的点的坐标.那么对于当前覆盖的线段\([l,r]\)…
题目链接:http://poj.org/problem?id=2528 题目大意:有一个很上的面板, 往上面贴海报, 问最后最多有多少个海报没有被完全覆盖 解题思路:将贴海报倒着想, 对于每一张海报只需要判断他要贴的位置是否已经全部被之前的海报覆盖就可以了, 如果没有被覆盖那么这个海报最后是没有被完全覆盖的, 如果被覆盖了, 那么最后是被完全覆盖的.标准的线段树题目. 代码如下: #include<stdio.h> #include<vector> #include<map&…