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 ...
随机推荐
- face detection[S^3FD]
本文来自<\(S^3\)FD: Single Shot Scale-invariant Face Detector>,时间线为2017年11月. 0 引言 基于锚的目标检测方法,是通过分类 ...
- 测试工具使用-Qunit单元测试使用过程
031302620 应课程要求写一篇单元测试工具的博客,但是暂时没用到java,所以不想使用junit(对各种类都不熟悉的也不好谈什么测试),原计划是要用phpunit,但是安装经历了三个小时,查阅各 ...
- 一致性环Hash算法.NET实现
一致性环Hash算法有一个大用处就是解决Memcache服务器down机问题的.目的是增加或者移除Memcache服务器后,最大限度的减少所受影响. 理论方面的就不介绍了,网上有太多资料了,请大家自己 ...
- 撒花!中文翻译仓库链接已加入 ML.NET 官方示例网站首页
从2018年12月02日决定开始做ML.NET 示例中文版https://github.com/feiyun0112/machinelearning-samples.zh-cn,然后以每天一篇的速度进 ...
- 面试:用 Java 实现一个 Singleton 模式
面试:用 Java 实现一个 Singleton 模式 面试系列更新后,终于迎来了我们的第一期,我们也将贴近<剑指 Offer>的题目给大家带来 Java 的讲解,个人还是非常推荐< ...
- H5 字符实体
41-字符实体 (greater than) © 版权符号 --> 我 爱你 到此为止我们的HTML的基础标签就学习完毕了, 例如我们学习了<h1>标签, <table&g ...
- 整数划分 poj3181
分析 因为n,m分别最大1000,100 所以结果会超过ll,要用两个来存大数的两部分 代码 #include<iostream> #include<algorithm> #i ...
- Jenkins部署net core小记
作为一个不熟悉linux命令的neter,在centos下玩Jenkins真的是一种折磨啊,但是痛并快乐着,最后还是把demo部署成功!写这篇文章是为了记录一下这次部署的流程,和心得体会. 网上很多资 ...
- mysql常用命令行操作(一):登陆、退出、查看端口、修改密码、刷新
一.登陆和退出mysql mysql -u root -p # 登陆exit # 退出 二.查看当前mysql的端口号 show global variables like 'port'; 三.查看用 ...
- Ubuntu端口开放
一.关于iptable的介绍 维基百科:https://zh.wikipedia.org/wiki/Iptables 注意:iptables的操作需要root权限 二.具体操作 sudo apt-ge ...