离散化/线段树 (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块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...
随机推荐
- HttpClient报错Timeout waiting for connection from pool
报错现象 线上项目使用HttpClient请求第三方的HTTP资源,并发量高的时候,日志框报Timeout waiting for connection from pool 客户端的现象是有时正常,有 ...
- SpringBoot核心注解:@SpringBootApplication
@SpringBootApplication它是由三个注解的复合: @ComponentScan @SpringConguration @EnableAutoConfiguration 三个注解的作用 ...
- 漆包线工厂生产管理MES系统解决方案
漆包线行业老板痛点: 1.漆包线比较传统的行业,一般都是靠人工去管理,老板想及时知道工厂的生产,销售.出入库.库存情况: 2.型号多称重打印易错,没有系统前 :称重打印,出入库,财务脱节,库存和 ...
- Linux SNMP监控配置
1, 安装SNMP服务 [root@zlm log]# yum -y install net-snmp net-snmp-utils 2, 编辑SNMP配置文件[root@zlm log]# vim ...
- Spring MVC的生命周期与简单三大组件的简单介绍
1.说到Spring MVC就会想到它是基于MVC设计模式的思想来设计的: 那么MVC设计模式是什么呢? 下面来介绍一下 MVC 设计模式 MVC是模型(model)-视图(view)-控制器(con ...
- Blazor入门100天 : 身份验证和授权之 OpenID 与 OAuth2
目录: OpenID 与 OAuth2 基础知识 Blazor wasm Gitee 码云登录 Blazor wasm GitHub 登录 Blazor wasm Google 登录 Blazor w ...
- 文心一言 VS chatgpt (21)-- h264编码一帧数据的流程是怎样的?
h264编码一帧数据的流程是怎样的? 文心一言: H.264编码将一帧数据分成多个块,其中每个块可以单独进行编码.编码的过程包括预测.变换和量化等步骤. 具体流程如下: 1.帧内预测:对一帧视频进行编 ...
- java中获取公网IP
package com.dashan.utils.iputils; import org.apache.commons.lang.StringUtils; import java.io.Buffere ...
- 一文带你了解两种Transformer文字识别方法
摘要:受Transformer模型的启发,目前一些学者将该结构应用到文本行识别中,以替代RNN,取得了良好的效果,如在HGA-STR和 SRN. 当前的文本行识别器为拥有更强的序列语义能力,模型多采用 ...
- 带你了解VXLAN网络中报文的转发机制
摘要:本节以集中式VXLAN网络(手工方式建立VXLAN隧道)为例,分别介绍相同子网内.不同子网间是如何进行通信的.在了解转发机制的前提下,我们先来看下VXLAN网关有哪些种类. VXLAN二层网关与 ...