hdu 5124(区间更新+单点求值+离散化)
lines
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1575 Accepted Submission(s): 656
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.
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.
5
1 2
2 2
2 4
3 4
5 1000
5
1 1
2 2
3 3
4 4
5 5
1
#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(区间更新+单点求值+离散化)的更多相关文章
- Kattis - Fenwick Tree(树状数组区间更新单点求值)
Fenwick Tree Input The first line of input contains two integers NN, QQ, where 1≤N≤50000001≤N≤500000 ...
- hdu 1556 Color the ball(线段树区间维护+单点求值)
传送门:Color the ball Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/3276 ...
- HDU - 3584 Cube (三维树状数组 + 区间改动 + 单点求值)
HDU - 3584 Cube Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Subm ...
- CDOJ 1059 秋实大哥与小朋友 STL(set)+离散化+BIT区间更新单点查询
链接: A - 秋实大哥与小朋友 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:%lld & %llu Subm ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- codevs 1081 线段树练习 2 区间更新 单点查询 无lazy
题目描述 Description 给你N个数,有两种操作 1:给区间[a,b]的所有数都增加X 2:询问第i个数是什么? 输入描述 Input Description 第一行一个正整数n,接下来n行n ...
- HDU 5861 Road 线段树区间更新单点查询
题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Road Time Limit: 12000/6000 MS (Java/Othe ...
- HDU 6356 (线段树-l,r 之间小于val 的变val+单点求值)
题目描述: 给你一个长度为n的最开始为0的数以及m个更新操作以及数据生成器参数X,Y,Z.每次操作,将由数据生成器生成出li,ri,vi.让你从区间[li,ri]中,将所有小于vi的数变为vi.最后让 ...
- POJ 2155 Matrix(二维树状数组+区间更新单点求和)
题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...
随机推荐
- https refused 解决方法
今天调试Android程序,所有的手机都ok,后来,我一个手机一直说,refused. 其实这就说明代码是没有问题的,你应该可以根据这个把代码的原因排除.然后剩下的,网络请求还能有什么,网路白. 果然 ...
- 2.ifconfig
转载http://www.cnblogs.com/peida/archive/2013/02/27/2934525.html 许多windows非常熟悉ipconfig命令行工具,它被用来获取网络接口 ...
- linux 检测进程是否存在
1. 直接遍历/proc目录 int find_pid_by_name( char* pidname, pid_t *pidlist) { #define READ_BUF_SIZE 256 DIR ...
- linux统计分析流量-wireshark
wireshark是一款带界面的开源抓包工具,可以用来对系统流量进行统计分析. 安装 由于wireshark是带界面的,所以一般在界面环境下运行,可以通过yum安装: $ yum install -y ...
- 二 APPIUM Android自动化 测试初体验
本文转自:http://www.cnblogs.com/sundalian/p/5629358.html 1.创建一个maven项目 成功新建工程: 编辑pom.xml,在<dependenci ...
- 孤荷凌寒自学python第五十五天初识MongoDb数据库
孤荷凌寒自学python第五十五天第一天初识MongoDb数据库 (完整学习过程屏幕记录视频地址在文末) 大家好,2019年新年快乐! 本来我想的是借新年第一天开始,正式尝试学习爬虫,结果今天偶然发现 ...
- ftrace 简介
ftrace 简介 ftrace 的作用是帮助开发人员了解 Linux 内核的运行时行为,以便进行故障调试或性能分析. 最早 ftrace 是一个 function tracer,仅能够记录内核的函数 ...
- Linux运维文档之nginx
NGINX安装配置1.检查并且安装依赖组件检查安装nginx的依赖性,nginx的模块需要第三方库的支持,检查是否安装下列库:zlib.zlib-devel.openssl.openssl-devel ...
- 根文件系统制作、NFS配置与安装及利用NFS挂载根文件系统
最近打算从头开始制作根文件系统,下面是开发过程. 一.根文件系统的制作 0.FHS(Filesystem Hierarchy Standard)标准介绍 该标准规定了根目录下各个子目录的名称及其存放的 ...
- [转]mysql联合索引
mysql联合索引 命名规则:表名_字段名1.需要加索引的字段,要在where条件中2.数据量少的字段不需要加索引3.如果where条件中是OR关系,加索引不起作用4.符合最左原则 https:/ ...