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 1753: [Usaco2005 qua]Who's in the Middle【排序】
--这可能是早年Pascal盛行的时候考排序的吧居然还是Glod-- #include<iostream> #include<cstdio> #include<algor ...
- 洛谷P5398 [Ynoi2018]GOSICK(二次离线莫队)
题面 传送门 题解 维包一生推 首先请确保您会二次离线莫队 那么我们现在的问题就是怎么转移了,对于\(i\)和前缀\([1,r]\)的贡献,我们拆成\(b_i\)和\(c_i\)两部分,其中\(b_i ...
- 一个完整的mybatis项目,包含增删改查
1.导入jar包,导入相关配置文件,均在自己博客园的文件中 编写mybatis.xml文件 <?xml version="1.0" encoding="UTF-8& ...
- 数据传递-------@PathVariable
package com.wh.handler; /** * 通过@PathVariable可以绑定占位符参数到方法参数中,例如 * @PathVariable("userId") ...
- dubbo面试题
40 道 Dubbo 面试题及答案:https://blog.csdn.net/BinshaoNo_1/article/details/83024303 (原地址奉上:https://mp.weixi ...
- Python学习日记之练习代码
# -*- coding:utf-8 -*- number = 23 test=True while test: guess=int(raw_input('输入数字')) if guess==numb ...
- Android基础TOP5_2:MultiAutoCompleteTextView多文本自动补全文本框
Activity: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmln ...
- PHP——基本使用(一)
Apache安装与配置 install 下载地址:https://www.apachelounge.com/download/,选择2.4.33版本64位 将程序解压到一个英文目录下,以管理身份打开c ...
- Solr搜索引擎 — 通过mysql配置数据源
一,准备数据库数据表结构 CREATE TABLE `app` ( `id` int(11) NOT NULL AUTO_INCREMENT, `app_name` varchar(255) NOT ...
- SQL关于触发器及存储过程的创建
使用T-SQL语句来创建触发器 基本语句如下﹕ create trigger trigger_name on {table_name | view_name} {for | After | Ins ...