离散化/线段树 (POJ - 2528 Mayor's posters)
Mayor's posters https://vjudge.net/problem/POJ-2528#author=szdytom
线段树 + 离散化
讲解:https://blog.csdn.net/qq_35802619/article/details/98326267
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define sc(n) scanf("%c",&n)
#define sd(n) scanf("%d",&n)
#define pd(n) printf("%d\n", (n))
#define sdd(n,m) scanf("%d %d",&n,&m)
#define pdd(n,m) printf("%d %d\n",n, m)
#define ms(a,b) memset(a,b,sizeof(a))
#define all(c) c.begin(),c.end()
typedef long long ll;
const int maxn = 2e5 + 5;//数组注意别开小了
struct node {
int l, r, gg;
}tr[maxn << 2 + 5];
int lg[maxn], rg[maxn];
int lisan[maxn];
int cnt, ans;
bool book[maxn];
void build(int p, int l, int r) {
tr[p].l = l, tr[p].r = r;
if (l == r) {
tr[p].gg = 0; return;
}
int m = (l + r) >> 1;
build(p << 1, l, m);
build(p << 1 | 1, m + 1, r);
tr[p].gg = 0;
}
void spread(int q) {
if (tr[q].gg == 0) return;
tr[q << 1].gg = tr[q].gg;
tr[q << 1 | 1].gg = tr[q].gg;
tr[q].gg = 0;
}
void update(int q, int l, int r, int v) {
if (l <= tr[q].l && r >= tr[q].r) {
tr[q].gg = v; return;
}
spread(q);
int m = (tr[q].l + tr[q].r) >> 1;
if (l <= m) update(q << 1, l, r, v);
if (r > m) update(q << 1 | 1, l, r, v);
}
void ask(int q, int l, int r)
{
if (tr[q].gg && !book[tr[q].gg])
{
ans++;
book[tr[q].gg] = 1;
return;
}
if (l == r) return;
spread(q);
int mid = (l + r) >> 1;
ask(q << 1, l, mid);
ask(q << 1 | 1, mid + 1, r);
}
int main() {
//freopen("in.txt", "r", stdin);
//ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t, n; sd(t);
while (t--) {
cnt = 0; ms(book, false); sd(n);
for (int i = 0; i < n; ++i) {
sdd(lg[i], rg[i]);
lisan[cnt++] = lg[i];
lisan[cnt++] = rg[i];
}
//离散化
sort(lisan, lisan + cnt);
int m = unique(lisan, lisan + cnt) - lisan;
int t0 = m;
for (int i = 1; i <= m; ++i)
if (lisan[i] - lisan[i - 1] > 1)lisan[t0++] = lisan[i - 1] + 1;
sort(lisan, lisan + t0);
build(1, 1, t0);
for (int i = 0; i < n; ++i) {
int x = lower_bound(lisan, lisan + t0, lg[i]) - lisan + 1;
int y = lower_bound(lisan, lisan + t0, rg[i]) - lisan + 1;
// cout <<x << " " << y << endl;
update(1, x, y, i + 1);
}
ans = 0;
ask(1, 1, t0);
printf("%d\n", ans);
}
return 0;
}
离散化/线段树 (POJ - 2528 Mayor's posters)的更多相关文章
- poj 2528 Mayor's posters(线段树+离散化)
/* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...
- poj 2528 Mayor's posters 线段树+离散化技巧
poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...
- POJ - 2528 Mayor's posters(dfs+分治)
POJ - 2528 Mayor's posters 思路:分治思想. 代码: #include<iostream> #include<cstdio> #include< ...
- POJ 2528 Mayor's posters 【区间离散化+线段树区间更新&&查询变形】
任意门:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ 2528 Mayor's posters(线段树+离散化)
Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...
- POJ 2528 - Mayor's posters - [离散化+区间修改线段树]
题目链接:http://poj.org/problem?id=2528 Time Limit: 1000MS Memory Limit: 65536K Description The citizens ...
- 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(线段树区间染色+离散化或倒序更新)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 59239 Accepted: 17157 ...
- POJ 2528 Mayor's posters (线段树区间更新+离散化)
题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...
随机推荐
- MODBUS转PROFINET网关TS-180 网关连接西门子 PLC 和工业称重仪表
随着科技的高速发展,工业自动化行业对日益多样的称重需求越来越高,上海某公司在国内的一个 工业自动化项目中,监控中心系统需要远程实时采集工业称重仪表测量的各种称重参数.该系统使用的是 西门子 S7-30 ...
- MySQL-安全更新参数
版权声明:原创作品,谢绝转载!否则将追究法律责任. ----- 作者:kirin 注意! 生产环境中,updata必须要加where条件 1.开启安全功能,会提示你加where,不加会提示语法不正确. ...
- MySQL大表设计怎么做?
MySQL是一种常用的关系型数据库管理系统,它在处理大表时需要特别注意设计和优化.下面将详细介绍MySQL大表的设计原则和优化策略. 1. 数据库设计 数据库范式化:将数据按照规范的关系模型进行拆分和 ...
- h5移动端使用video实现拍照、上传文件对象、选择相册,做手机兼容。
html部分 <template> <div class="views"> <video style="width: 100vw; heig ...
- 基于DotNetty实现自动发布 - 项目的配置与发现
前言 上一篇,我们实现了基于 DotNetty 的通信基础模块的搭建,本篇,主要实现待发布 Web 项目的集成. 创建待发布项目 为了测试, 我创建了一个基于 .NET 4.8 的 Web 项目 Op ...
- Linux笔记03: Linux常用命令_3.2目录操作命令
3.2 目录操作命令 3.2.1 ls命令 ●命令名称:ls. ●英文原意:list directory contents. ●所在路径:/usr/bin/ls. ●执行权限:所有用户. ●功能描述: ...
- [AGC59C] Guessing Permutation for as Long as Possible
Problem Statement A teacher has a hidden permutation $P=(P_1,P_2,\ldots,P_N)$ of $(1,2,\cdots,N)$. Y ...
- 数据智慧:C#中编程实现自定义计算的Excel数据透视表
前言 数据透视表(Pivot Table)是一种数据分析工具,通常用于对大量数据进行汇总.分析和展示.它可以帮助用户从原始数据中提取关键信息.发现模式和趋势,并以可视化的方式呈现. 在数据透视表中,数 ...
- APP性能测试-客户端性能测试
https://blog.csdn.net/xiaomaoxiao336368/article/details/83547318
- ElasticSearch之查看集群的参数
参考Cluster get settings API. 命令样例,不指定参数,如下: curl -X GET "https://localhost:9200/_cluster/setting ...