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. 1
  2. 5
  3. 1 4
  4. 2 6
  5. 8 10
  6. 3 4
  7. 7 10

Output for sample input

  1. 4
  2.  
  3. 解题:线段树+离散化。挂了几次,居然还有贴在10-10这样位置的数据,简直太疯狂了。。这能贴么,一个点啊!好吧,改正后,终于Ac 了。
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <climits>
  7. #include <vector>
  8. #include <queue>
  9. #include <cstdlib>
  10. #include <string>
  11. #include <set>
  12. #include <stack>
  13. #include <map>
  14. #define LL long long
  15. #define pii pair<int,int>
  16. #define INF 0x3f3f3f3f
  17. using namespace std;
  18. const int maxn = ;
  19. set<int>st;
  20. int a[maxn],b[maxn];
  21. struct node{
  22. int lt,rt,flag;
  23. };
  24. node tree[maxn<<];
  25. int lisan[maxn<<];
  26. void build(int lt,int rt,int v){
  27. tree[v].lt = lt;
  28. tree[v].rt = rt;
  29. tree[v].flag = ;
  30. if(lt + == rt) return;
  31. int mid = (lt+rt)>>;
  32. build(lt,mid,v<<);
  33. build(mid,rt,v<<|);
  34. }
  35. void update(int lt,int rt,int v,int val){
  36. if(lisan[tree[v].lt] == lt && lisan[tree[v].rt] == rt){
  37. tree[v].flag = val;
  38. return;
  39. }
  40. if(tree[v].flag){
  41. tree[v<<].flag = tree[v<<|].flag = tree[v].flag;
  42. tree[v].flag = ;
  43. }
  44. int mid = (tree[v].lt+tree[v].rt)>>;
  45. if(rt <= lisan[mid]){
  46. update(lt,rt,v<<,val);
  47. }else if(lt >= lisan[mid]){
  48. update(lt,rt,v<<|,val);
  49. }else{
  50. update(lt,lisan[mid],v<<,val);
  51. update(lisan[mid],rt,v<<|,val);
  52. }
  53. }
  54. void query(int v){
  55. if(tree[v].flag){
  56. if(!st.count(tree[v].flag)) st.insert(tree[v].flag);
  57. return;
  58. }
  59. if(tree[v].lt+ == tree[v].rt) return;
  60. query(v<<);
  61. query(v<<|);
  62. }
  63. int main() {
  64. int t,i,j,n,cnt,tot;
  65. scanf("%d",&t);
  66. while(t--){
  67. tot = ;
  68. scanf("%d",&n);
  69. for(i = ; i <= n; i++){
  70. scanf("%d %d",a+i,b+i);
  71. if(a[i] > b[i]) swap(a[i],b[i]);
  72. lisan[tot++] = a[i];
  73. lisan[tot++] = ++b[i];
  74. }
  75. sort(lisan+,lisan+tot);
  76. cnt = ;
  77. for(i = ; i < tot; i++){
  78. if(lisan[i] == lisan[cnt]) continue;
  79. lisan[++cnt] = lisan[i];
  80. }
  81. build(,cnt,);
  82. for(i = ; i <= n; i++) update(a[i],b[i],,i);
  83. st.clear();
  84. query();
  85. printf("%d\n",st.size());
  86. }
  87. return ;
  88. }

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. HTML5牛刀小试

    第一周的HTML5苦逼之路,就这么简单,充实,忙碌的开始了,丝毫不敢有一丢丢懈怠,压力是有的,但更多的是对自己的信心,更是对自己的踏上苦逼之路的意志的肯定. 简单回顾了下这周所学内容.从认识HTML基 ...

  2. 近年来火热的人工智能,其实是IT业界的一个障眼法

    近年来火热的人工智能,其实是IT业界的一个障眼法,仗着现在的计算机的计算能力牛B,把一个类仿生统计算法,宣传成了人工智能,不得不感叹一些营销人士的牛逼,说大话不腰疼.当然谎言重复一千遍也许自己也就信了 ...

  3. php生成唯一订单号的方法

    第一种 $danhao = date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT); 第二种 $danhao = date('Ym ...

  4. (分治)51NOD 1019 逆序数

    在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序.一个排列中逆序的总数就称为这个排列的逆序数.   如2 4 3 1中,2 1,4 3,4 1,3 1是 ...

  5. python程序展现图片

    突然想写一个python程序能够显示图片的 ,展示文字的已经实现了 现在就搞一搞这个吧 相信也是很简单 首先是放一张图片在e盘下面 等会程序打包的时候将会用到 就决定是你啦 皮卡丘: 然后就写代码吧:

  6. c# 线程浅析(代理 、Invoke、Lock)

    前言:本来想根据自己的经验总结一下c#线程相关的知识点, 写之前看了一些其他人的博客,发现自己也就掌握了不到三分之一....希望通过这次的博客将自己的知识点补充一下,写出更直白的博客和初学者分享. 这 ...

  7. Objective-C设计模式——外观Faced(接口适配)

    外观模式 外观设计模式和适配器差不多,不过它门对对象控制的粒度不同,适配器一般只是控制一个系统和客户端的对接.外观则是用来抽象多个系统一起工作. 外观一般具有多个子系统,所以外观应持有多个子系统的引用 ...

  8. poj1778 All Discs Considered

    思路: 拓扑排序.贪心. 实现: #include <bits/stdc++.h> using namespace std; vector<]; int n1, n2; inline ...

  9. SAS进阶《深入分析SAS》之数据汇总和展现

    SAS进阶<深入分析SAS>之数据汇总和展现 1. 通过Print过程制作报表 proc print <data=数据集>; run; 选项: obs=修改观测序号列标签 no ...

  10. pyhon模块

    模块基础 什么是模块 模块式一系列功能的集合体,而函数是某一个功能的集合体,因此模块可以看成是一堆函数的集合体.一个py文件内部可以放一堆函数,因此一个py文件就可以看成是一个模块.如果这个py文件的 ...