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 (离散化+线段树区间修改)的更多相关文章

  1. POJ 2528 ——Mayor's posters(线段树+区间操作)

    Time limit 1000 ms Memory limit 65536 kB Description The citizens of Bytetown, AB, could not stand t ...

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

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

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

    题目链接: 传送门 Mayor's posters Time Limit: 1000MS     Memory Limit: 65536K Description The citizens of By ...

  4. POJ 2528——Mayor's posters——————【线段树区间替换、找存在的不同区间】

    Mayor's posters Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

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

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

  6. 【POJ】2528 Mayor's posters ——离散化+线段树

    Mayor's posters Time Limit: 1000MS    Memory Limit: 65536K   Description The citizens of Bytetown, A ...

  7. (中等) POJ 2528 Mayor's posters , 离散+线段树。

    Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...

  8. POJ 2528 Mayor's posters(线段树染色问题+离散化)

    http://poj.org/problem?id=2528 题意: 给出一面无限长的墙,现在往墙上依次贴海报,问最后还能看见多少张海报. 题意:这道题目就相当于对x轴染色,然后计算出最后还能看见多少 ...

  9. POJ 2528 Mayor's posters(线段树)

    点我看题目 题意 :建一堵墙粘贴海报,每个候选人只能贴一张海报,海报的高度与墙一样高,一张海报的宽度是整数个单位,墙被划分为若干个部分,每个部分的宽度为一个单位,每张海报完全的覆盖一段连续的墙体,墙体 ...

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

    http://poj.org/problem?id=2528 https://www.luogu.org/problem/UVA10587 Description The citizens of By ...

随机推荐

  1. 【C++】实现一个简单的单例模式

  2. web 压力测试工具

    最近有收到任务,测试新服务器的性能. 花了很长时间做搜索,也整理了一些资料.以下是收集到一些简单易用的分析工具.推荐给大家使用. WebBenchhttp://www.ha97.com/4623.ht ...

  3. 【Tsinsen A1339】JZPLCM (树状数组)

    Description 原题链接 ​ 给定一长度为\(~n~\)的正整数序列\(~a~\),有\(~q~\)次询问,每次询问一段区间内所有数的\(~LCM~\)(即最小公倍数).由于答案可能很大,输出 ...

  4. Hdoj 1050.Moving Tables 题解

    Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a buildin ...

  5. [luogu4139]上帝与集合的正确用法【欧拉定理+扩展欧拉定理】

    题目大意 让你求\(2^{2^{2^{\cdots}}}(mod)P\)的值. 前置知识 知识1:无限次幂怎么解决 让我们先来看一道全国数学竞赛的一道水题: 让你求解:\(x^{x^{x^{\cdot ...

  6. [poj1160][IOI2000]Post Office【动态规划】

    传送门 https://vjudge.net/problem/POJ-1160#author=SCU2018 题目描述 在一条水平的公路上建有n个小屋,两个小屋间的距离是它们的横坐标之差的绝对值.保证 ...

  7. [ZJOI2007]仓库建设(斜率优化)

    L公司有N个工厂,由高到底分布在一座山上. 工厂1在山顶,工厂N在山脚. 由于这座山处于高原内陆地区(干燥少雨),L公司一般把产品直接堆放在露天,以节省费用. 突然有一天,L公司的总裁L先生接到气象部 ...

  8. struts2 对EL的改变

    Struts2对EL的改变 1.Struts2中使用EL的问题: 前提: 我们应该知道,如果我们没有往值栈(根)中放入数据的话,那么我们的动作类默认是在值栈的栈顶 2.关于EL问题的分析: 分析:   ...

  9. jquery+ajax无刷新加载数据,新闻浏览更多

      <script type="text/javascript"> $(document).ready(function (){ $(window).scroll(fu ...

  10. POJ 1639 Picnic Planning 最小k度生成树

    Picnic Planning Time Limit: 5000MS   Memory Limit: 10000K Total Submissions:11615   Accepted: 4172 D ...