这道题最关键的点就在离散化吧。

假如有三张海报[1, 10] [10, 13][15,  20] 仅仅三个区间就得占用到20了。

但是离散化后就可以是[1, 2] [2, 3] [4, 5] n到1e4 不重叠的话最大也只到2e4

那么就可以做了

离散化技巧需要好好消化

代码如下

#include <cstring>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define lp p<<1
#define rp p<<1|1
using namespace std;
const int N = +;
int tree[N<<];
int a[N], ans;
bool vis[N];
pair<int,int> p[N]; inline void pushdown(int p) {
if (tree[p]) {
tree[lp] = tree[rp] = tree[p];
tree[p] = ;
}
}
void build(int p, int l, int r) {
if (tree[p]) {
if (!vis[tree[p]]) {
vis[tree[p]] = ;
ans++;
}
return;
}
int mid = l + r >> ;
build(lp, l, mid);
build(rp, mid + , r);
}
void change(int p, int l, int r, int x, int y, int z) {
if (x <= l && y >= r) {
tree[p] = z;
return;
}
pushdown(p);
int mid = l + r >> ;
if (x <= mid) change(lp, l, mid, x, y, z);
if (y > mid) change(rp, mid + , r, x, y, z);
}
int main()
{
int T; scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &n);
for (int i = ; i <= * n; i++) {
scanf("%d", &p[i].first);
p[i].second = i;
}
sort(p + , p + * n + );
int last = , cnt = ;
for (int i = ; i <= * n; i++) {
if (p[i].first == last) {
a[p[i].second] = cnt;
} else {
a[p[i].second] = ++cnt, last = p[i].first;
}
}
memset(tree, , sizeof(tree));
for (int i = ; i <= * n; i += ) {
change(, , cnt, a[i], a[i+], (i + ) / );
}
memset(vis, , sizeof(vis));
ans = ;
build(, , cnt);
printf("%d\n", ans);
}
return ;
}

Mayor's posters(线段树+离散化)的更多相关文章

  1. POJ 2528 Mayor's posters(线段树+离散化)

    Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...

  2. poj 2528 Mayor's posters 线段树+离散化技巧

    poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...

  3. Mayor's posters (线段树+离散化)

    Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...

  4. [poj2528] Mayor's posters (线段树+离散化)

    线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayor ...

  5. Mayor's posters(线段树+离散化POJ2528)

    Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 51175 Accepted: 14820 Des ...

  6. POJ 2528 Mayor's posters (线段树+离散化)

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:75394   Accepted: 21747 ...

  7. poj 2528 Mayor's posters 线段树+离散化 || hihocode #1079 离散化

    Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...

  8. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

  9. poj-----(2528)Mayor's posters(线段树区间更新及区间统计+离散化)

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 43507   Accepted: 12693 ...

  10. POJ2528:Mayor's posters(线段树区间更新+离散化)

    Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...

随机推荐

  1. bootstrapvalidator 用法

    1.引入js.css 2.用法 API:http://bootstrapvalidator.votintsev.ru/api/ 参考博客:https://blog.csdn.net/u01393846 ...

  2. Mybatis学习总结(六)——高级映射(一对一,一对多,多对多)

    一.订单商品数据模型 1.数据库执行脚本 创建数据库表代码: /*Table structure for table `t_user` */ CREATE TABLE t_user ( id INT ...

  3. springcloud(十三):Eureka 2.X 停止开发,但注册中心还有更多选择:Consul 使用详解

    在上个月我们知道 Eureka 2.X 遇到困难停止开发了,但其实对国内的用户影响甚小,一方面国内大都使用的是 Eureka 1.X 系列,另一方面 Spring Cloud 支持很多服务发现的软件, ...

  4. .NetCore 资料分享

    .NetCore3.0 你还不打算入手么? 这次主要是推荐一些自己学习中遇到的一些好的资料和自己的看法( 我推荐的都是我看过的 Asp.Net Core 不做介绍了,直接分享资料了 资料: .NetC ...

  5. functools下的partial模块应用

    问题 你有一个被其他python代码使用的callable对象,可能是一个回调函数或者是一个处理器, 但是它的参数太多了,导致调用时出错. 解决方案 如果需要减少某个函数的参数个数,你可以使用 fun ...

  6. 剑指Offer-- 二叉搜索树的后序遍历序列判断

    版本1:C++ class Solution { public: bool VerifySquenceOfBST(vector<int> sequence) { ) return fals ...

  7. Rimworld单人生存记

    开局什么也没有,第一天按原来的墙造了个卧室差不多就完了,可见工作效率之低.花了三四天才种好水稻+草莓,做了短弓,挖了一些钢铁,造了燃料炉灶和屠宰台.第五天来了个人,我用短弓和他打,问题是远程最多打一下 ...

  8. PS提亮户外儿童照

    (@摄影师延延)作品 调整完的图. 原图. 再看原图.好吧,这张照片明显欠曝了,蘑菇酱的小脸黑黑的.但是构图啊蘑菇酱的神情啊都不错捏.好在蘑菇妈是用raw格式拍,即刻Lightroom调整无压力. 1 ...

  9. Django之在Python中调用Django环境

    Django之在Python中调用Django环境 新建一个py文件,在其中写下如下代码: import os if __name__ == '__main__': os.environ.setdef ...

  10. BOM、DOM

    window对象 所有浏览器都支持window对象,他表示浏览器窗口. 全局变量是window对象的属性.全局函数是window对象的方法. window的常用方法: window.innerHeig ...