G - Mayor's posters POJ - 2528

这个题目要倒着来写,从后面往前面贴,因为前面的有些会被后面的覆盖。

所以我们就判断这张海报的位置有没有完全被覆盖,如果完全被覆盖了就不能贴,但是没有完全被覆盖就可以贴上去,然后更新掉这一段。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 1e5 + ;
pair<int, int>pii[maxn];
int a[maxn];
struct node {
int l, r, lazy;
}tree[maxn * ]; void push_up(int id) {
if (tree[id << ].lazy&&tree[id << | ].lazy) tree[id].lazy = ;
} void push_down(int id) {
if (tree[id].lazy) {
tree[id << ].lazy = ;
tree[id << | ].lazy = ;
}
} void build(int id, int l, int r) {
tree[id].l = l;
tree[id].r = r;
tree[id].lazy = ;
if (l == r) return;
int mid = (l + r) >> ;
build(id << , l, mid);
build(id << | , mid + , r);
} int query(int id, int l, int r) {
//printf("id=%d \n", id);
if (l <= tree[id].l&&r >= tree[id].r) {
if (tree[id].lazy) return ;
return ;
}
push_down(id);
int ans = ;
int mid = (tree[id].l + tree[id].r) >> ;
if (l <= mid) ans = max(ans, query(id << , l, r));
if (r > mid) ans = max(ans, query(id << | , l, r));
return ans;
} void update(int id, int l, int r) {
if (l <= tree[id].l&&r >= tree[id].r) {
tree[id].lazy = ;
return;
}
push_down(id);
int mid = (tree[id].l + tree[id].r) >> ;
if (l <= mid) update(id << , l, r);
if (r > mid) update(id << | , l, r);
push_up(id);
} int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, cnt = ;
scanf("%d", &n);
for (int i = ; i <= n; i++) {
int x, y;
scanf("%d%d", &x, &y);
pii[i] = make_pair(x, y);
a[++cnt] = x;
a[++cnt] = x - ;
a[++cnt] = x + ;
a[++cnt] = y - ;
a[++cnt] = y;
a[++cnt] = y + ;
}
sort(a + , a + + cnt);
int size = unique(a + , a + + cnt) - (a + );
build(, , size);
// for(int i=1;i<=size;i++)
// {
// printf("i=%d %d\n", i, a[i]);
// }
int ans = ;
for (int i = n; i >= ; i--) {
int l = pii[i].first, r = pii[i].second;
int t1 = lower_bound(a + , a + + size, l) - a;
int t2 = lower_bound(a + , a + + size, r) - a;
//printf("%d %d\n", t1, t2);
if (query(, t1, t2)) {
ans++;
update(, t1, t2);
}
}
printf("%d\n", ans);
}
return ;
}
												

线段树 G - Mayor's posters 小技巧的更多相关文章

  1. 线段树---poj2528 Mayor’s posters【成段替换|离散化】

    poj2528 Mayor's posters 题意:在墙上贴海报,海报可以互相覆盖,问最后可以看见几张海报 思路:这题数据范围很大,直接搞超时+超内存,需要离散化: 离散化简单的来说就是只取我们需要 ...

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

    离散化其实就是把所有端点放在一起,然后排序去个重就好了. 比如说去重以后的端点个数为m,那这m个点就构成m-1个小区间.然后给这m-1个小区间编号1~m-1,再用线段树来做就行了. 具体思路是,从最后 ...

  3. poj2528(线段树+离散化)Mayor's posters

    2016-08-15 题意:一面墙,往上面贴海报,后面贴的可以覆盖前面贴的.问最后能看见几种海报. 思路:可以理解成往墙上涂颜色,最后能看见几种颜色(下面就是以涂色来讲的).这面墙长度为1~1000 ...

  4. 【线段树】Mayor's posters

    [poj2528]Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 66154   Accept ...

  5. (线段树)Mayor's posters --poj -- 2528

    链接: http://poj.org/problem?id=2528 覆盖问题, 要从后往前找, 如果已经被覆盖就不能再覆盖了,否则就可以覆盖 递归呀递归什么时候我才能吃透你 代码: #include ...

  6. 线段树维护区间前k小

    线段树维护区间前k小 $ solution: $ 觉得超级钢琴太麻烦?在这里线段树提供一条龙服务 . 咳咳,开始讲正题!这道题我们有一个和超级钢琴复杂度一样 $ ~O(~\sum x\times lo ...

  7. poj2886(线段树求序列第k小)

    题目链接:https://vjudge.net/problem/POJ-2886 题意:n个人围成一个圈,每个人有姓名s和权值val两个属性,第一轮序号为k的人退出,并根据其val指定下一个人,val ...

  8. poj2828(线段树查找序列第k小的值)

    题目链接:https://vjudge.net/problem/POJ-2828 题意:有n个人,依次给出这n个人进入队列时前面有多少人p[i],和它的权值v[i],求最终队列的权值序列. 思路:基本 ...

  9. poj2182(线段树求序列第k小)

    题目链接:https://vjudge.net/problem/POJ-2182 题意:有n头牛,从1..n编号,乱序排成一列,给出第2..n个牛其前面有多少比它编号小的个数,记为a[i],求该序列的 ...

随机推荐

  1. stand up meeting 1/14/2016

    part 组员                工作              工作耗时/h 明日计划 工作耗时/h    UI 冯晓云  主要对生词本卡片的整体设计做修改:协助主程序完成popup部分 ...

  2. 杭电 逃离迷宫 BFS

    给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有些地方是障碍,她必须绕行,从迷宫的一个位 ...

  3. idea ------- 源码调试运行

    1.创建一个 想学 的 ,使用单步调试进行一步步学习 调整系统资源 单步调试 (F7) ,进入不了源码,调整idea 让我们可以进入底层学习 想要在源码里面添加注释,要将引用的源文件指向,我们刚才复制 ...

  4. vue2.x学习笔记(九)

    接着前面的内容:https://www.cnblogs.com/yanggb/p/12577948.html. 数组的更新检测 数组在javascript是一种特殊的对象,不是像普通的对象那样通过Ob ...

  5. Linux-Deepin 下开启SSH远程登陆

    #### 关于deepin系统安装ssh后,root超级用户登录报错的完美解决方案! 最近刚刚接触到deepin,觉得,wow,除了mac,还有这么好看的非win系统,而且第测出那个Linux,宽容度 ...

  6. 靠!安装了macOS Catalina(10.15.4)后,文件系统都乱套了

    最近闲来无事,决定将我的两台apple电脑升级成最新的苹果系统(macOS Catalina),当然,由于以前升级过多次mac系统,所以毫不犹豫从app store下载了最新的macOS Cetali ...

  7. vscode 使用记录

    快捷键 Cmd+P 查找最近的文件 Ctrl+cmd + P 打开命令面板 Ctrl+tab文件间切换 Ctrl+` 打开终端 Cmd +b 隐藏侧边栏 VScode对多行编辑有两种模式 第一种模式 ...

  8. react: typescript jest && enzyme

    Install Jest 1.install jest dependencies jest @types/jest ts-jest -D 2.jest.config.js module.exports ...

  9. spring boot连接linux服务器上的redis

    本文章为给新手学习spring boot远程连通redis提供一个学习参考. 环境是intellij idea(window)+ redis(linux虚拟机-vmware). 首先在linux安装好 ...

  10. 不使用tomcat,仅适用javaSE手写服务器--模拟登陆

    1.搭建框架 我们只是简单模拟,框架简单分三个模块 a,服务器端server包 b,servlet,根据不同的请求url,利用反射生产对应的servlet c,IO工具包,用来关闭IO流 d,编写we ...