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 所以离散化一下。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include <queue>
using namespace std;
const int N = ;
int a[N],b[N],x[*N];
int c[*N];
int n;
int MAX ; int lowbit(int x){
return x&-x;
}
void update(int idx,int v){
for(int i=idx;i<=*n;i+=lowbit(i)){
c[i] +=v;
}
}
int getsum(int idx){
int sum = ;
for(int i=idx;i>=;i-=lowbit(i)){
sum+=c[i];
}
return sum;
}
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--){
memset(c,,sizeof(c));
scanf("%d",&n);
int cnt = ;
for(int i=;i<=n;i++){
scanf("%d%d",&a[i],&b[i]);
x[cnt++] = a[i];
x[cnt++] = b[i];
}
int k = ;
sort(x+,x+cnt);
for(int i=;i<cnt;i++){
if(x[i]==x[i-]) continue;
x[k++] = x[i];
}
for(int i=;i<=n;i++){
int l = lower_bound(x+,x+k,a[i])-(x);
int r = lower_bound(x+,x+k,b[i])-(x);
update(l,);
update(r+,-);
}
int MAX = -;
for(int i=;i<=*n;i++){
MAX = max(MAX,getsum(i));
}
printf("%d\n",MAX);
}
return ;
}

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. Windows+Python 3.6环境下安装PyQt4

    第一步:下载.whl,地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyqt4,这里可以下载不同的python版本对应的包. 第二步:选择一个目录,将下 ...

  2. python学习笔记-参数带*

    #!/usr/bin/python # -*- coding: utf-8 -*- def powersum (power,*args): #所有多余的参数都会作为一个元组存储在args中     s ...

  3. Spider_Man_6 の Scrapy_Downloader Middleware(针对一下🐷🐷🐷)

    下载器中间件(Downloader Middleware) 下载器中间件是介于Scrapy的request/response处理的钩子框架.是用于全局修改Scrapy request和response ...

  4. CodeBlocks X64 SVN 编译版

    CodeBlocks X64 SVN 编译版 采用官方最新的SVN源码编译而来,纯64位的,所以32位系统是不能使用的.字体使用的是微软的YaHei UI字体,如果有更好的字节建议,可以留言. 由于直 ...

  5. CodeForces Round #515 Div.3 C. Books Queries

    http://codeforces.com/contest/1066/problem/C You have got a shelf and want to put some books on it. ...

  6. KNN算法在保险业精准营销中的应用

    版权所有,可以转载,禁止修改.转载请注明作者以及原文链接. 一.KNN算法概述 KNN是Machine Learning领域一个简单又实用的算法,与之前讨论过的算法主要存在两点不同: 它是一种非参方法 ...

  7. [2018-9-4T2]探索黑暗dark

    题目大意:有一棵树,第$i$个点的点权为$s_i(s_1>0)$.初始有每个点都是亮的.$m$次修改,每次改变一个点的亮暗,回答包含$1$的全亮的连通块中点权和最大的连通块的和的值. 题解:正解 ...

  8. 湘潭邀请赛 2018 E From Tree to Graph

    题意: 给出一棵树以及m,a,b,x0,y0.之后加m条边{(x1,LCA(x1,y1)),(x2,LCA(x2,y2))...(xm,LCA(xm,ym))}.定义z = f(0)^f(1)^... ...

  9. ccpc 网络赛 hdu 6155

    # ccpc 网络赛 hdu 6155(矩阵乘法 + 线段树) 题意: 给出 01 串,要么询问某个区间内不同的 01 子序列数量,要么把区间翻转. 叉姐的题解: 先考虑怎么算 \(s_1, s_2, ...

  10. hdu 6102 GCDispower

    多校6 GCDispower(容斥) 题意: 给一个长度为\(n\)的排列 给q组询问 每次查询\(L,R\)内的答案 \(\sum_{i=L}^{R}\sum_{j=i+1}^{R}\sum_{k= ...