Mayor's posters(线段树+离散化)
这道题最关键的点就在离散化吧。
假如有三张海报[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(线段树+离散化)的更多相关文章
- POJ 2528 Mayor's posters(线段树+离散化)
Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...
- poj 2528 Mayor's posters 线段树+离散化技巧
poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...
- Mayor's posters (线段树+离散化)
Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...
- [poj2528] Mayor's posters (线段树+离散化)
线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayor ...
- Mayor's posters(线段树+离散化POJ2528)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 51175 Accepted: 14820 Des ...
- POJ 2528 Mayor's posters (线段树+离散化)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions:75394 Accepted: 21747 ...
- poj 2528 Mayor's posters 线段树+离散化 || hihocode #1079 离散化
Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...
- poj-----(2528)Mayor's posters(线段树区间更新及区间统计+离散化)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 43507 Accepted: 12693 ...
- POJ2528:Mayor's posters(线段树区间更新+离散化)
Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...
随机推荐
- 不可变对象和Biulder模式(面试问题)
String就是一个典型的不可变对象.外界的操作不能改变它,如果尝试改变都会返回一个新的String对象. 具体实现起来就是把属性全部变成private 和 final的,这个类也是final的不可继 ...
- 总结一下linux中的分段机制
本文为原创,转载请注明:http://www.cnblogs.com/tolimit/ 这篇文章主要说一下linux对于分段机制的处理,虽然都说linux不使用分段机制,但是分段机制属于CPU的一个功 ...
- windows下数据挖掘相关包numpy、pandas的安装
安装Anaconda的绕道 这里介绍如何在windows下安装numpy/scipy/matplotlib/pandas/scikit_learn等数据分析相关包 相关环境: win7 64位 pyt ...
- BZOJ1023 SHOI2008 仙人掌图 仙人掌、单调队列
传送门 求仙人掌的直径,可以由求树的直径进行拓展,只需要在环上特殊判断. 沿用求树的直径的DP,对于一条不在任何环内的边,直接像树的直径一样转移,然后考虑环的影响. 设环长为\(cir\),在\(df ...
- Spring Cloud 入门教程(六): 用声明式REST客户端Feign调用远端HTTP服务
首先简单解释一下什么是声明式实现? 要做一件事, 需要知道三个要素,where, what, how.即在哪里( where)用什么办法(how)做什么(what).什么时候做(when)我们纳入ho ...
- 朱晔的互联网架构实践心得S2E4:小议微服务的各种玩法(古典、SOA、传统、K8S、ServiceMesh)
十几年前就有一些公司开始践行服务拆分以及SOA,六年前有了微服务的概念,于是大家开始思考SOA和微服务的关系和区别.最近三年Spring Cloud的大火把微服务的实践推到了高潮,而近两年K8S在容器 ...
- C#使用ILGenerator动态生成函数
游戏服务器里面总是有一大堆的配置文件需要读取, 而且这些配置文件的读取: * 要不然做成弱类型的, 就是一堆字符串或者数字, 不能看出来错误(需要重新检测一次) * 要不然做成强类型的, 每种类型都需 ...
- 01 Django REST Framework 介绍
01-Django REST Framework的介绍 Django REST框架是一个用于构建Web API的强大而灵活的工具包. 您可能希望使用REST框架的一些原因: 1. Web可浏览API对 ...
- Selenium库
'''自动化测试工具,支持多种浏览器.爬虫中主要用来解决JavaScrip渲染的问题.''''''基本使用'''from selenium import webdriverfrom selenium. ...
- JSP页面的基本元素
JSP页面元素构成:静态内容.指令.表达式.小脚本.声明.注释. JSP指令包括: page指令:通常位于jsp页面的顶端,同一个页面可以有多个page指令. include指令:将一个外部文件嵌入到 ...