lines

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1575    Accepted Submission(s): 656

Problem Description
John
has several lines. The lines are covered on the X axis. Let A is a
point which is covered by the most lines. John wants to know how many
lines cover A.
 
Input
The first line contains a single integer T(1≤T≤100)(the data for N>100 less than 11 cases),indicating the number of test cases.
Each test case begins with an integer N(1≤N≤105),indicating the number of lines.
Next N lines contains two integers Xi and Yi(1≤Xi≤Yi≤109),describing a line.
 
Output
For each case, output an integer means how many lines cover A.
 
Sample Input
2
5
1 2
2 2
2 4
3 4
5 1000
5
1 1
2 2
3 3
4 4
5 5
 
Sample Output
3
1
 
Source
 
题意:一些线段互相覆盖,求这个线段上面的覆盖线段数最多的点被多少线段覆盖??
题解:看到线段就想到区间更新,然后看到点就想到单点求值,然后只有100000个线段,但是范围却有 1 - 10^9 所以离散化一下。
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<cmath>
  6. #include <queue>
  7. using namespace std;
  8. const int N = ;
  9. int a[N],b[N],x[*N];
  10. int c[*N];
  11. int n;
  12. int MAX ;
  13.  
  14. int lowbit(int x){
  15. return x&-x;
  16. }
  17. void update(int idx,int v){
  18. for(int i=idx;i<=*n;i+=lowbit(i)){
  19. c[i] +=v;
  20. }
  21. }
  22. int getsum(int idx){
  23. int sum = ;
  24. for(int i=idx;i>=;i-=lowbit(i)){
  25. sum+=c[i];
  26. }
  27. return sum;
  28. }
  29. int main()
  30. {
  31. int tcase;
  32. scanf("%d",&tcase);
  33. while(tcase--){
  34. memset(c,,sizeof(c));
  35. scanf("%d",&n);
  36. int cnt = ;
  37. for(int i=;i<=n;i++){
  38. scanf("%d%d",&a[i],&b[i]);
  39. x[cnt++] = a[i];
  40. x[cnt++] = b[i];
  41. }
  42. int k = ;
  43. sort(x+,x+cnt);
  44. for(int i=;i<cnt;i++){
  45. if(x[i]==x[i-]) continue;
  46. x[k++] = x[i];
  47. }
  48. for(int i=;i<=n;i++){
  49. int l = lower_bound(x+,x+k,a[i])-(x);
  50. int r = lower_bound(x+,x+k,b[i])-(x);
  51. update(l,);
  52. update(r+,-);
  53. }
  54. int MAX = -;
  55. for(int i=;i<=*n;i++){
  56. MAX = max(MAX,getsum(i));
  57. }
  58. printf("%d\n",MAX);
  59. }
  60. return ;
  61. }

hdu 5124(区间更新+单点求值+离散化)的更多相关文章

  1. Kattis - Fenwick Tree(树状数组区间更新单点求值)

    Fenwick Tree Input The first line of input contains two integers NN, QQ, where 1≤N≤50000001≤N≤500000 ...

  2. hdu 1556 Color the ball(线段树区间维护+单点求值)

    传送门:Color the ball Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/3276 ...

  3. HDU - 3584 Cube (三维树状数组 + 区间改动 + 单点求值)

    HDU - 3584 Cube Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Subm ...

  4. CDOJ 1059 秋实大哥与小朋友 STL(set)+离散化+BIT区间更新单点查询

    链接: A - 秋实大哥与小朋友 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Subm ...

  5. HDU.1556 Color the ball (线段树 区间更新 单点查询)

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

  6. codevs 1081 线段树练习 2 区间更新 单点查询 无lazy

    题目描述 Description 给你N个数,有两种操作 1:给区间[a,b]的所有数都增加X 2:询问第i个数是什么? 输入描述 Input Description 第一行一个正整数n,接下来n行n ...

  7. HDU 5861 Road 线段树区间更新单点查询

    题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Road Time Limit: 12000/6000 MS (Java/Othe ...

  8. HDU 6356 (线段树-l,r 之间小于val 的变val+单点求值)

    题目描述: 给你一个长度为n的最开始为0的数以及m个更新操作以及数据生成器参数X,Y,Z.每次操作,将由数据生成器生成出li,ri,vi.让你从区间[li,ri]中,将所有小于vi的数变为vi.最后让 ...

  9. POJ 2155 Matrix(二维树状数组+区间更新单点求和)

    题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...

随机推荐

  1. Javascript Step by Step - 02

    DOM 操作 DOM是面向HTML和XML文档的API,为文档提供了结构化表示.在DOM中一切都是节点Node,文档就是由许多的Node组成的.文档里的每个节点都有属性 nodeName.nodeVa ...

  2. pg数据库数据表异常挂起

    pg数据库即是PostgreSQL数据库. 前几天在一个Java项目中,出现运行Java程序后,pg数据库的数据表异常挂起.而且是在某台电脑上出现的,重装数据库也没用,其它电脑未能复现,是个很奇怪的现 ...

  3. 成员变量和属性区别(@property那点事儿)

    历史由来: 接触iOS的人都知道,@property声明的属性默认会生成一个_类型的成员变量,同时也会生成setter/getter方法. 但这只是在iOS5之后,苹果推出的一个新机制.看老代码时,经 ...

  4. js限制文本框只能输入特定字符

    限制只能输入数字 // ---------------------------------------------------------------------- // <summary> ...

  5. spring 笔记2:Spring MVC : Did not find handler method for 问题的解决

    日志显示为: Looking up handler method for path /***Did not find handler method for [/***]No mapping found ...

  6. JS——BOM、DOM

    BOM.DOM BOM window对象 history对象 location对象 screen对象 DOM DOM对HTML元素访问操作 HTML DOM树 DOM 节点 DOM访问HTML元素 D ...

  7. RMAN 增量备份级别说明

    通过Bat批处理调用RMan是我们定时备份数据库的好帮手,但是RMan的备份级别需要我们好好了解一下. RMAN备份全为全备和增量备份 增量备份:分为0 1 2级 ORACLE官方解释: A leve ...

  8. 第二阶段团队冲刺-seven

    昨天: 合并程序(添加打印txt). 今天: 整体调试程序继续优化. 遇到的问题: 解决前两天的问题.

  9. Json对象转json数组

    var arr = [];             arr.push(strData);

  10. nf_register_hooks解读

    nf_register_hooks是什么 net->netns_nf->nf_hook_entry[NFPROTO_NUMPROTO][NF_MAX_HOOKS=8] (nf)       ...