解题报告

id=2528">地址传送门

题意:

一些海报,覆盖上去后还能看到几张。

思路:

第一道离散化的题。

离散化的意思就是区间压缩然后映射。

给你这么几个区间[1,300000],[3,5],[6,10],[4,9]

区间左右坐标排序完就是

1,3,4,5,6,9,10,300000;

1,2,3,4,5,6, 7 ,8;

我们能够把上面的区间映射成[1,8],[2,4],[5,7],[3,6];

这样就节省了非常多空间。

给线段染色, lz标记颜色。

#include <map>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
struct node
{
int x,y;
} p[10100];
int zb[20100],_hash[10100],lz[100000],ans;
void push_down(int root )
{
if(lz[root])
{
lz[root*2]=lz[root*2+1]=lz[root];
lz[root]=0;
}
}
void update(int root,int l,int r,int ql,int qr,int v)
{
if(ql>r||qr<l)return;
if(ql<=l&&r<=qr)
{
lz[root]=v;
return;
}
push_down(root);
int mid=(l+r)/2;
update(root*2,l,mid,ql,qr,v);
update(root*2+1,mid+1,r,ql,qr,v);
}
void _q(int root,int l,int r)
{
if(lz[root])
{
if(!_hash[lz[root]])
ans++;
_hash[lz[root]]=1;
return ;
}
if(l==r)return;
int mid=(l+r)/2;
_q(root*2,l,mid);
_q(root*2+1,mid+1,r);
}
int main()
{
int t,i,j,n;
scanf("%d",&t);
while(t--)
{
ans=0;
memset(_hash,0,sizeof(_hash));
scanf("%d",&n);
for(i=0; i<n; i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
zb[i]=p[i].x;
zb[i+n]=p[i].y;
}
sort(zb,zb+n*2);
int m=unique(zb,zb+n*2)-zb;
for(i=0; i<n; i++)
{
int ql=lower_bound(zb,zb+m,p[i].x)-zb+1;
int qr=lower_bound(zb,zb+m,p[i].y)-zb+1;
update(1,1,m,ql,qr,i+1);
}
_q(1,1,m);
printf("%d\n",ans);
}
}

Mayor's posters
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 41877   Accepted: 12199

Description

The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an electoral wall for placing the posters
and introduce the following rules:

  • Every candidate can place exactly one poster on the wall.
  • All posters are of the same height equal to the height of the wall; the width of a poster can be any integer number of bytes (byte is the unit of length in Bytetown).
  • The wall is divided into segments and the width of each segment is one byte.
  • Each poster must completely cover a contiguous number of wall segments.

They have built a wall 10000000 bytes long (such that there is enough place for all candidates). When the electoral campaign was restarted, the candidates were placing their posters on the wall and their posters differed widely in width. Moreover, the candidates
started placing their posters on wall segments already occupied by other posters. Everyone in Bytetown was curious whose posters will be visible (entirely or in part) on the last day before elections. 

Your task is to find the number of visible posters when all the posters are placed given the information about posters' size, their place and order of placement on the electoral wall. 

Input

The first line of input contains a number c giving the number of cases that follow. The first line of data for a single case contains number 1 <= n <= 10000. The subsequent n lines describe the posters in the order in which they were placed. The i-th line among
the n lines contains two integer numbers li and ri which are the number of the wall segment occupied by the left end and the right end of the i-th poster, respectively. We know that for each 1 <= i <= n, 1 <= li <= ri <= 10000000. After
the i-th poster is placed, it entirely covers all wall segments numbered li, li+1 ,... , ri.

Output

For each input data set print the number of visible posters after all the posters are placed. 



The picture below illustrates the case of the sample input. 

Sample Input

1
5
1 4
2 6
8 10
3 4
7 10

Sample Output

4

POJ训练计划2528_Mayor&#39;s posters(线段树/成段更新+离散化)的更多相关文章

  1. POJ 2777 Count Color (线段树成段更新+二进制思维)

    题目链接:http://poj.org/problem?id=2777 题意是有L个单位长的画板,T种颜色,O个操作.画板初始化为颜色1.操作C讲l到r单位之间的颜色变为c,操作P查询l到r单位之间的 ...

  2. poj 3468 A Simple Problem with Integers 【线段树-成段更新】

    题目:id=3468" target="_blank">poj 3468 A Simple Problem with Integers 题意:给出n个数.两种操作 ...

  3. 线段树(成段更新) POJ 3468 A Simple Problem with Integers

    题目传送门 /* 线段树-成段更新:裸题,成段增减,区间求和 注意:开long long:) */ #include <cstdio> #include <iostream> ...

  4. poj 3648 线段树成段更新

    线段树成段更新需要用到延迟标记(或者说懒惰标记),简单来说就是每次更新的时候不要更新到底,用延迟标记使得更新延迟到下次需要更新or询问到的时候.延迟标记的意思是:这个区间的左右儿子都需要被更新,但是当 ...

  5. ACM: Copying Data 线段树-成段更新-解题报告

    Copying Data Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description W ...

  6. Codeforces Round #149 (Div. 2) E. XOR on Segment (线段树成段更新+二进制)

    题目链接:http://codeforces.com/problemset/problem/242/E 给你n个数,m个操作,操作1是查询l到r之间的和,操作2是将l到r之间的每个数xor与x. 这题 ...

  7. hdu 4747【线段树-成段更新】.cpp

    题意: 给出一个有n个数的数列,并定义mex(l, r)表示数列中第l个元素到第r个元素中第一个没有出现的最小非负整数. 求出这个数列中所有mex的值. 思路: 可以看出对于一个数列,mex(r, r ...

  8. HDU1698_Just a Hook(线段树/成段更新)

    解题报告 题意: 原本区间1到n都是1,区间成段改变成一个值,求最后区间1到n的和. 思路: 线段树成段更新,区间去和. #include <iostream> #include < ...

  9. HDU 3577 Fast Arrangement ( 线段树 成段更新 区间最值 区间最大覆盖次数 )

    线段树成段更新+区间最值. 注意某人的乘车区间是[a, b-1],因为他在b站就下车了. #include <cstdio> #include <cstring> #inclu ...

随机推荐

  1. java反射bean to bean

    /** * Copyright © 2018 fwz Info. Tech Ltd. All rights reserved. * * @Package: com.sm.utils * @author ...

  2. JSONObject 自定义过滤配置

    一.自定义过滤器说明 PropertyPreFilter 根据PropertyName判断是否序列化  PropertyFilter 根据PropertyName和PropertyValue来判断是否 ...

  3. [教程] Spring+Mybatis环境配置多数据源

    一.简要概述 在做项目的时候遇到需要从两个数据源获取数据,项目使用的Spring + Mybatis环境,看到网上有一些关于多数据源的配置,自己也整理学习一下,然后自动切换实现从不同的数据源获取数据功 ...

  4. asp.net core 中的SignalR与web前端进行实时通信

    一.介绍 SignalR是.net 开源库,用于构建需要实时进行用户交互和数据更新的web应用,如在线聊天,游戏,天气等实时应用程序,且简化了构建实时应用的过程,包括服务端库和js端库,继承了数种常见 ...

  5. 数据包编辑工具bittwiste

    数据包编辑工具bittwiste   bittwiste是数据包重放工具bittwist的一个工具.该工具可以编辑修改PCAP抓包文件.该工具提供数据包过滤功能,如根据范围和时间过滤.同时,该工具支持 ...

  6. 内存缓存 ehcache

    内存缓存需要对内存缓存每个参数的配置意义搞明白,才能很好地去使用,例如失效时间.存活时间. 是否存储在磁盘.是否永久有效,参数要了解清楚后进行使用,不要在不清楚时盲目使用,会导致意想不到 的问题发生. ...

  7. BZOJ4003 JLOI2015城池攻占

    用左偏树模拟攻占的过程,维护最小值,最多入和出m次,每次log复杂度. #include<bits/stdc++.h> using namespace std; ; typedef lon ...

  8. beta6

    吴晓晖(组长) 过去两天完成了哪些任务 对手写输入进行了重构,然后重新捋了一下bayes的思路 展示GitHub当日代码/文档签入记录 接下来的计划 推荐算法 还剩下哪些任务 过去两天完成了哪些任务: ...

  9. [POJ1144]Network

    来源:Central Europe 1996 思路:Tarjan求割点. 一个点$x$为割点当且仅当: 1.$x$为根结点且有两棵不相交的子树. 2.$x$不为根结点且它的子树中没有可以返回到$x$的 ...

  10. hdu 4452 37届金华赛区 K题

    题意:给一个n*n的格子,1在左上角,2在右下角,每个人有一个初始速度和方向,若遇到边缘,则朝相反方向前进,若两个人相遇则交换方向(注意方向改变后,人仍然需要移动),同时,每个人每过t1,t2时间就会 ...