BNUOJ 2528 Mayor's posters
Mayor's posters
This problem will be judged on UVA. Original ID: 10587
64-bit integer IO format: %lld Java class name: Main
- 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.
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.
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
Output for sample input
4 解题:线段树+离散化。挂了几次,居然还有贴在10-10这样位置的数据,简直太疯狂了。。这能贴么,一个点啊!好吧,改正后,终于Ac 了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#include <map>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
set<int>st;
int a[maxn],b[maxn];
struct node{
int lt,rt,flag;
};
node tree[maxn<<];
int lisan[maxn<<];
void build(int lt,int rt,int v){
tree[v].lt = lt;
tree[v].rt = rt;
tree[v].flag = ;
if(lt + == rt) return;
int mid = (lt+rt)>>;
build(lt,mid,v<<);
build(mid,rt,v<<|);
}
void update(int lt,int rt,int v,int val){
if(lisan[tree[v].lt] == lt && lisan[tree[v].rt] == rt){
tree[v].flag = val;
return;
}
if(tree[v].flag){
tree[v<<].flag = tree[v<<|].flag = tree[v].flag;
tree[v].flag = ;
}
int mid = (tree[v].lt+tree[v].rt)>>;
if(rt <= lisan[mid]){
update(lt,rt,v<<,val);
}else if(lt >= lisan[mid]){
update(lt,rt,v<<|,val);
}else{
update(lt,lisan[mid],v<<,val);
update(lisan[mid],rt,v<<|,val);
}
}
void query(int v){
if(tree[v].flag){
if(!st.count(tree[v].flag)) st.insert(tree[v].flag);
return;
}
if(tree[v].lt+ == tree[v].rt) return;
query(v<<);
query(v<<|);
}
int main() {
int t,i,j,n,cnt,tot;
scanf("%d",&t);
while(t--){
tot = ;
scanf("%d",&n);
for(i = ; i <= n; i++){
scanf("%d %d",a+i,b+i);
if(a[i] > b[i]) swap(a[i],b[i]);
lisan[tot++] = a[i];
lisan[tot++] = ++b[i];
}
sort(lisan+,lisan+tot);
cnt = ;
for(i = ; i < tot; i++){
if(lisan[i] == lisan[cnt]) continue;
lisan[++cnt] = lisan[i];
}
build(,cnt,);
for(i = ; i <= n; i++) update(a[i],b[i],,i);
st.clear();
query();
printf("%d\n",st.size());
}
return ;
}
BNUOJ 2528 Mayor's posters的更多相关文章
- poj 2528 Mayor's posters(线段树+离散化)
/* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...
- poj 2528 Mayor's posters 线段树+离散化技巧
poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...
- POJ - 2528 Mayor's posters(dfs+分治)
POJ - 2528 Mayor's posters 思路:分治思想. 代码: #include<iostream> #include<cstdio> #include< ...
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...
- POJ 2528 Mayor's posters 【区间离散化+线段树区间更新&&查询变形】
任意门:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total S ...
- 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:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- 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 (线段树+离散化)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions:75394 Accepted: 21747 ...
随机推荐
- bzoj 4031: [HEOI2015]小Z的房间【矩阵树定理】
是板子题,因为mod不是质数所以需要辗转相除然而并不知道为啥 高斯消元部分还不知道原理呢--先无脑背过的 #include<iostream> #include<cstdio> ...
- [Swift通天遁地]一、超级工具-(14)使用SweetAlert制作漂亮的自定义Alert窗口
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- [C++ STL] 常用算法总结
1 概述 STL算法部分主要由头文件<algorithm>,<numeric>,<functional>组成.要使用 STL中的算法函数必须包含头文件<alg ...
- 笔记本 windows 10 安装
开机按快捷键是F12,选择从usb启动.秋叶系统 很好用,推荐使用. 联想笔记本u深度一键u盘启动BIOS设置教程:准备工作:制作好u深度u盘启动盘http://rj.baidu.com/soft/d ...
- ora-20000 unable to analyze
ora-20000 unable to analyze 无法分析表 check: select * from wmsprdata.cmp3$88278表不存在. result:应该是系统自动任务2:0 ...
- 01-Entity FrameWork如何控制数据的变化
在Entity Framework所有操作数据就是更新EF容器中的实体状态 public enum EntityState { Added = , Deleted = , Detached = , M ...
- from scipy import spatial 出现 from .qhull import * ImportError: DLL load failed: The specified module could not be found. 错误
错误描述: 本人机器window8.1 64位,python2.7. Traceback (most recent call last): File "C:/Users/Hamid/Docu ...
- jQuery中$this和$(this)的区别
要写一个点击弹窗任意地方,关闭弹窗.点击事件写标签在元素上 onclick = closepop(this),这时候很容易搞不清楚怎么去获取当前元素 function closepop(e){ va ...
- 在中间层 .NET 应用程序中通过授权管理器使用基于角色的安全
基于角色的安全是从 Windows NT 的第一个版本开始在 Windows 平台上发展而来的.使用角色,操作系统可以通过检查称为 BUILTIN\Administrators 的组的安全上下文做出一 ...
- glassfish中新建数据源(创建数据库连接池)
1.浏览器输入:http://localhost:4848 登录glassfish域管理控制台,默认的用户名和密码是amin和adminadmin.(也可以通过NetBeans的服务选项卡--服务器- ...