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)的更多相关文章

  1. poj 2528 Mayor's posters(线段树+离散化)

    /* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...

  2. poj 2528 Mayor's posters 线段树+离散化技巧

    poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...

  3. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

  4. POJ - 2528 Mayor's posters(dfs+分治)

    POJ - 2528 Mayor's posters 思路:分治思想. 代码: #include<iostream> #include<cstdio> #include< ...

  5. POJ 2528 Mayor's posters 【区间离散化+线段树区间更新&&查询变形】

    任意门:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  6. POJ 2528 Mayor's posters(线段树+离散化)

    Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...

  7. POJ 2528 - Mayor's posters - [离散化+区间修改线段树]

    题目链接:http://poj.org/problem?id=2528 Time Limit: 1000MS Memory Limit: 65536K Description The citizens ...

  8. poj 2528 Mayor's posters 线段树+离散化 || hihocode #1079 离散化

    Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...

  9. POJ 2528 Mayor's posters(线段树区间染色+离散化或倒序更新)

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 59239   Accepted: 17157 ...

  10. POJ 2528 Mayor's posters (线段树区间更新+离散化)

    题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...

随机推荐

  1. python,opencv-python人脸识别,并且发邮件对镜头前未知人员进行报警

    我们在任意一个硬盘的根目录下创建一个Code-project文件夹 在该文件夹下分别创建C-project和Python-project文件夹 在Python-project文件夹下创建face re ...

  2. uni-app框架开发app发布流程

    uni-app框架开发app发布流程 1.首先公司申请软著 步骤:申请软著详细流程 - 阿长*长 - 博客园 (cnblogs.com) 一.安卓端 1,点击发行>原生-app云打包 正式包和自 ...

  3. MySQL-utf8 和 utf8mb4 区别?

    版权声明:原创作品,谢绝转载!否则将追究法律责任. ----- 作者:kirin 1.首先说明一下,版本问题.MySQL8.0之后默认:utf8mb4,而8.0之前默认:latin 2.utf8 和 ...

  4. 现代统计分析软件Datainside在学生成绩分析中的应用

    Datainside(薪火数据)是一款非常常用的统计分析软件,广泛应用于学术研究和商业领域. 在学生成绩分析方面,Datainside提供了丰富的功能和工具,可以帮助教育机构和研究人员深入理解学生的学 ...

  5. 文心一言 VS 讯飞星火 VS chatgpt (149)-- 算法导论12.2 4题

    五.用go语言,证明:如果一棵二叉搜索树中的一个结点有两个孩子,那么它的后继没有左孩子,它的前驱没有右孩子. 灵捷3.5 . 文心一言: 为了证明这个性质,我们首先需要明确二叉搜索树(BST)的定义和 ...

  6. C#中的并行处理、并行查询的方法你用对了吗?

    Parallel.ForEach Parallel.ForEach 是一个用于在集合上并行执行迭代操作的强大工具.它通过有效地利用多核处理器的能力来提高性能.Parallel.ForEach 不仅能够 ...

  7. scrum|敏捷开发之任务看板

    上篇文章中,我讲了敏捷第一步-每日站立会,讲了我们平时是怎么开站立会的,其实15-30分钟就够了,绝对不是时间长得让你想拄拐那种.本文我们开始讲敏捷开发中的看板.没有看板之前,我们真的是在白板上画泳道 ...

  8. excute方法和submit方法

    区别:   1.参数     execute  Runnable     submit     Callable   2.返回值     execute :void     submit :Futur ...

  9. vue-test ------事件监听

    <template> <h3>监听器</h3> <p>{{message}}</p> <button @click="upd ...

  10. 【问题解决】unable to do port forwarding: socat not found

    问题复现 前阵子应公司要求做华为云平台的调研,写了一篇文档包含将华为云CCE下载kuberctl配置及使用kubectl转发流量到本地的操作. 今天一早上同事就发来一个错误界面,说是Java远程调试转 ...