POJ - 2528 Mayor's posters (离散化+线段树区间修改)
https://cn.vjudge.net/problem/POJ-2528
题意
给定一些海报,可能相互重叠,告诉你每个海报的宽度(高度都一样的)和先后叠放顺序,问没有被完全盖住的有多少张?
分析
海报最多10000张,但是墙有10000000块瓷砖长,海报不会落在瓷砖中间。
如果直接建树,就算不TLE,也会MLE。即单位区间长度太多。
其实10000张海报,有20000个点,最多有19999个区间。对各个区间编号,就是离散化。然后建树。
可以直接进行区间修改,最后再统计。
这里采用比较巧妙的方法,倒着来统计,每次看这个将覆盖的区间是否已经完全被覆盖了。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define eps 0.0000000001
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define random(a, b) rand()*rand()%(b-a+1)+a
#define pi acos(-1)
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
const int maxn = + ;
const int maxm = + ;
const int mod = ; pii poster[maxn];
int x[maxn<<];
int Hash[];
struct ND{
int l,r;
bool covered;
}tree[maxn<<];
void build(int rt,int l,int r){
tree[rt].l=l;
tree[rt].r=r;
tree[rt].covered=false;
if(l==r) return;
int mid = (l+r)>>;
build(rt<<,l,mid);
build(rt<<|,mid+,r);
} void pushup(int rt){
tree[rt].covered=tree[rt<<].covered&tree[rt<<|].covered;
} bool update(int rt,double l,double r){
if(tree[rt].covered) return false;
if(l<=tree[rt].l&&r>=tree[rt].r) return tree[rt].covered=true;
bool res;
if(tree[rt<<].r>=r) res=update(rt<<,l,r);
else if(l>=tree[rt<<|].l) res=update(rt<<|,l,r);
else{
bool b1=update(rt<<,l,tree[rt<<].r);
bool b2=update(rt<<|,tree[rt<<|].l,r);
res=b1||b2;
}
pushup(rt);
return res;
}
int n;
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int T,cas=;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
int cnt=;
for(int i=;i<n;i++){
scanf("%d%d",&poster[i].first,&poster[i].second);
x[cnt++]=poster[i].first;
x[cnt++]=poster[i].second;
}
sort(x,x+cnt);
cnt=unique(x,x+cnt)-x;
build(,,cnt-);
for(int i=;i<cnt;i++) Hash[x[i]]=i;
int res=;
for(int i=n-;i>=;i--){
if(update(,Hash[poster[i].first],Hash[poster[i].second]))
res++;
}
printf("%d\n",res);
}
return ;
}
---恢复内容结束---
POJ - 2528 Mayor's posters (离散化+线段树区间修改)的更多相关文章
- POJ 2528 ——Mayor's posters(线段树+区间操作)
Time limit 1000 ms Memory limit 65536 kB Description The citizens of Bytetown, AB, could not stand t ...
- POJ 2528 Mayor's posters(线段树区间染色+离散化或倒序更新)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 59239 Accepted: 17157 ...
- POJ 2528 Mayor's posters(线段树/区间更新 离散化)
题目链接: 传送门 Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Description The citizens of By ...
- POJ 2528——Mayor's posters——————【线段树区间替换、找存在的不同区间】
Mayor's posters Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- poj 2528 Mayor's posters(线段树+离散化)
/* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...
- 【POJ】2528 Mayor's posters ——离散化+线段树
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Description The citizens of Bytetown, A ...
- (中等) POJ 2528 Mayor's posters , 离散+线段树。
Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...
- POJ 2528 Mayor's posters(线段树染色问题+离散化)
http://poj.org/problem?id=2528 题意: 给出一面无限长的墙,现在往墙上依次贴海报,问最后还能看见多少张海报. 题意:这道题目就相当于对x轴染色,然后计算出最后还能看见多少 ...
- POJ 2528 Mayor's posters(线段树)
点我看题目 题意 :建一堵墙粘贴海报,每个候选人只能贴一张海报,海报的高度与墙一样高,一张海报的宽度是整数个单位,墙被划分为若干个部分,每个部分的宽度为一个单位,每张海报完全的覆盖一段连续的墙体,墙体 ...
- POJ-2528 Mayor's posters(线段树区间更新+离散化)
http://poj.org/problem?id=2528 https://www.luogu.org/problem/UVA10587 Description The citizens of By ...
随机推荐
- gogs : 添加 ssh An error has occurred : addKey: fail to parse public key: exec: "ssh-keygen": executable file not found in %PATH% - exec: "ssh-keygen": executable file not found in %PATH%
服务器上缺少配置 ssh-keygen.exe的 环境变量.git的环境变量 在path 环境变量加上.重启gogs服务
- Hdoj 2501.Tiling_easy version 题解
Problem Description 有一个大小是 2 x n 的网格,现在需要用2种规格的骨牌铺满,骨牌规格分别是 2 x 1 和 2 x 2,请计算一共有多少种铺设的方法. Input 输入的第 ...
- 【BZOJ5300】[CQOI2018]九连环 (高精度,FFT)
[BZOJ5300][CQOI2018]九连环 (高精度,FFT) 题面 BZOJ 洛谷 题解 去这里看吧,多么好 #include<iostream> #include<cstdi ...
- CF1106E Lunar New Year and Red Envelopes
比赛时看到这题懵逼了,比完赛仔细一想是个很简单的dp = = 由于题目限制,可以发现\(B\)取红包的策略是唯一的,可以用优先队列预处理出\(B\)在第\(i\)秒可以拿到的红包的收益\(w_i\)和 ...
- 20165223 结对编程之四则运算week2-整体总结
目录 一.结对对象 二.需求分析 三.设计思路 四.核心代码 五.功能截图 六.结对感受 一.结对对象 担任角色(本周交换角色,流动学习) 驾驶员(Driver):20165218 赵冰雨(是控制键盘 ...
- Ubuntu18.04 下的Gif录制工具
正文: 开源地址:https://github.com/phw/peek Linux包相关的知识如果不知道可以看以前讲的:https://www.cnblogs.com/dunitian/p/9095 ...
- sh: /etc/init.d/sshd: not found Docker中的Alpine镜像安装sshd无法启动
问题描述 在Alpine镜像中安装了openssh-server和openssh之后,无法执行ssh localhost.发现未启动服务,开启服务时报以下错误 / # ls /etc/init.d/s ...
- react-native中使用长列表
React Native 提供了几个适用于展示长列表数据的组件,一般而言我们会选用FlatList或是SectionList. FlatList组件用于显示一个垂直的滚动列表,其中的元素之间结构近似而 ...
- Fiddler安装证书
1.打开Fiddler,点击工具栏中的Tools——>Fiddler Options… 2.切换到 HTTPS 选项卡,勾选 Capture HTTPS CONNECTs,勾选 De ...
- js数组歌
判断是不是数组,isArray最靠谱. 按照条件来判断,every/some给答案 是否包含此元素,includes最快速. find/findIndex很相似,按条件给第一个值. indexOf/l ...