Mayor's posters

Time Limit: 3000ms
Memory Limit: 131072KB

This problem will be judged on UVA. Original ID: 10587
64-bit integer IO format: %lld      Java class name: Main

 
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.

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 lili+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的更多相关文章

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

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

  2. poj 2528 Mayor's posters 线段树+离散化技巧

    poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...

  3. POJ - 2528 Mayor's posters(dfs+分治)

    POJ - 2528 Mayor's posters 思路:分治思想. 代码: #include<iostream> #include<cstdio> #include< ...

  4. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

  5. POJ 2528 Mayor's posters 【区间离散化+线段树区间更新&&查询变形】

    任意门:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total S ...

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

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

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

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

  8. POJ 2528 Mayor's posters

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

  9. POJ 2528 Mayor's posters (线段树+离散化)

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

随机推荐

  1. php 批量检测bom头,去除bom头工具

    <?php //有些php文件由于不小心保存成了含bom头的格式而导致出现一系列的问题.以下是批量清除bom头的代码 if (isset ( $_GET ['dir'] )) { //confi ...

  2. [App Store Connect帮助]六、测试 Beta 版本(4.1) 管理 Beta 版构建版本:为构建版本添加测试员

    在“TestFlight”部分中,您可以查看您所有 App 版本的构建版本,并深入查看构建版本的详细信息.您也可以为某个构建版本添加群组或独立测试员. 必要职能:“帐户持有人”职能.“管理”职能或“A ...

  3. INT类型知多少

    前言: 整型是MySQL中最常用的字段类型之一,通常用于存储整数,其中int是整型中最常用的,对于int类型你是否真正了解呢?本文会带你熟悉int类型相关知识,也会介绍其他整型字段的使用. 1.整型分 ...

  4. gitlab&Jenkins 详细介绍及其应用

    第1章 gitlab 1.1 系统环境 [root@jenkins ~]# cat  /etc/redhat-release CentOS Linux release 7.2.1511 (Core) ...

  5. tomcat 参数调优

    JAVA_OPTS="-Xms2g -Xmx2g  -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath= ...

  6. ssh&amp;远程桌面连接工具finalshell

    无意间发现的一款工具,有兴趣的可以看看点我进入官网 百度云盘 链接:https://pan.baidu.com/s/1wMuGav64e2zV91QznBkvag 密码:zpyb软件特点直接搬运的官方 ...

  7. Linux环境下RPM包相互依赖的解决办法

    Linux环境下安装Oracle11gR2提示缺少"Package: elfutils-libelf-devel-0.125    FAILED"包,按照提示安装该包时又提示缺少依 ...

  8. Android 性能优化(18)JNI优化:JNI Tips 提升性能技巧

    JNI Tips 1.In this document JavaVM and JNIEnv Threads jclass, jmethodID, and jfieldID Local and Glob ...

  9. ORACLE批量绑定FORALL与BULK COLLECT

    FORALL与BULK COLLECT的使用方法: 1.使用FORALL比FOR效率高,因为前者只切换一次上下文,而后者将是在循环次数一样多个上下文间切换. 2.使用BLUK COLLECT一次取出一 ...

  10. sublime 3 最新注册码

    http://9iphp.com/web/html/sublime-text-3-license-key.html