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

假如有三张海报[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. 在Ubuntu上快速搭建基于Beego的RESTful API

    最近在研究Go,打算基于Go做点Web API,于是经过初步调研,打算用Beego这个框架,然后再结合其中提供的ORM以及Swagger的集成,可以快速搭建一个RESTful API的网站. 下面是具 ...

  2. Nginx(二)------nginx.conf 配置文件

    上一篇博客我们将 nginx 安装在 /usr/local/nginx 目录下,其默认的配置文件都放在这个目录的 conf 目录下,而主配置文件 nginx.conf 也在其中,后续对 nginx 的 ...

  3. 如何备份和恢复你的TFS服务器(三)

    进行一次备份 当然,如果你已经建立了一个时间表,那么备份会在指定的时间自动地进行,但是我真的无法给你展示一张很酷的截图——那是不可见的:).无论你是否建立了一个时间表.你都可以在任意时间执行一次完整的 ...

  4. samba故障:protocol negotiation failed: NT_STATUS_IO_TIMEOUT

    windows下无法访问samba共享目录,若无任何提示则需要到linux服务器上访问samba共享,看下是否有问题提示 故障解决过程:(保证网络通畅) 1.查看samba服务器是否正常,smb服务器 ...

  5. Ubuntu Desktop: 备份与还原

    Ubuntu Desktop 版本默认自带了图形化的备份/还原工具 Déjà Dup.该工具主要用来备份和还原用户的数据,当然我们也可以用它来备份/还原系统的数据.本文主要介绍 Déjà Dup 的主 ...

  6. Python全栈开发之路 【第十六篇】:jQuey的动画效果、属性操作、文档操作、input的value

    01-动画效果 show 显示 概念:显示隐藏的匹配元素 语法:show(speed,callback) 参数: speed:三种预定速度之一的字符串('slow','normal','fast')或 ...

  7. Linux查看端口

    1.lsof -i:端口号 用于查看某一端口的占用情况,比如查看8000端口使用情况,lsof -i:8000   2.netstat -tunlp |grep 端口号 用于查看指定的端口号的进程情况 ...

  8. group by用法

    select * from Table group by id,一定不能是*,而是某一个列或者某个列的聚合函数. 参考:http://www.cnblogs.com/jingfengling/p/59 ...

  9. sql 表值函数与标量值函数

    写sql存储过程经常需要调用一些函数来使处理过程更加合理,也可以使函数复用性更强,不过在写sql函数的时候可能会发现,有些函数是在表值函数下写的有些是在标量值下写的,区别是表值函数只能返回一个表,标量 ...

  10. message:GDI+ 中发生一般性错误。

    图片类型的文件保存的时候出了问题,可能是路径出错,也可能是保存到的文件夹不存在导致(发布项目的时候如果文件夹是空的,文件夹将不存在)