题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5124

题意:给你n段区间,他们有重合的点A,问你重合最多次的点A重合多少次

题解:对区间离散化后,维护区间最大值

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define LL long long
#define MAX 100100
using namespace std;
int s[MAX],e[MAX],q[MAX];
int rec[MAX];//记录所有值排序后的下标
int add[MAX<<2];
int sum[MAX<<2];
int le[MAX],ri[MAX];
void pushup(int o)
{
sum[o]=max(sum[o<<1],sum[o<<1|1]);
}
void pushdown(int o,int m)
{
if(add[o])
{
add[o<<1]+=add[o];
add[o<<1|1]+=add[o];
sum[o<<1]+=add[o];
sum[o<<1|1]+=add[o];
add[o]=0;
}
}
void gettree(int o,int l,int r)
{
add[o]=0;
if(l==r)
{
sum[o]=0;
return ;
}
int mid=(l+r)>>1;
gettree(o<<1,l,mid);
gettree(o<<1|1,mid+1,r);
pushup(o);
}
void update(int o,int l,int r,int L,int R,int val)
{
if(L<=l&&R>=r)
{
add[o]+=val;
sum[o]+=val;
return ;
}
pushdown(o,r-l+1);
int mid=(l+r)>>1;
if(L<=mid)
update(o<<1,l,mid,L,R,val);
if(R>mid)
update(o<<1|1,mid+1,r,L,R,val);
pushup(o);
} int query(int l,int r,int pos)//查找输入当前值,在树中对应的位置
{
while(r>=l)
{
int mid=(l+r)>>1;
if(rec[mid]==pos)
return mid;
else if(rec[mid]>pos)
r=mid-1;
else
l=mid+1;
}
return -1;
}
int main()
{
int t,n,m,k,i;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int p=1;
for(i=0;i<n;i++)
{
scanf("%d%d",&s[i],&e[i]);
rec[p++]=s[i];
rec[p++]=e[i];
}
for(i=0;i<m;i++)
{
scanf("%d",&q[i]);
rec[p++]=q[i];
}
sort(rec+1,rec+p);//
int R=2;
for(i=2;i<p;i++)//去除数组中重复的点
{
if(rec[i]!=rec[i-1])
rec[R++]=rec[i];
}
sort(rec+1,rec+R);
gettree(1,1,R-1);//对下标建树
for(int i=0;i<n;i++)
{
int x=query(1,R-1,s[i]);
int y=query(1,R-1,e[i]);
update(1,1,R-1,x,y,1);
}
printf("%d\n",sum[1]);
}
}

  

hdoj 5124 lines【线段树+离散化】的更多相关文章

  1. hdoj 4325 Flowers 线段树+离散化

    hdoj 4325 Flowers 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4325 思路: 直接线段树,按照花的开放区间的大小建树,要注意虽然 ...

  2. UVa 1471 Defense Lines - 线段树 - 离散化

    题意是说给一个序列,删掉其中一段连续的子序列(貌似可以为空),使得新的序列中最长的连续递增子序列最长. 网上似乎最多的做法是二分查找优化,然而不会,只会值域线段树和离散化... 先预处理出所有的点所能 ...

  3. HDU5124:lines(线段树+离散化)或(离散化思想)

    http://acm.hdu.edu.cn/showproblem.php?pid=5124 Problem Description John has several lines. The lines ...

  4. [poj2528] Mayor's posters (线段树+离散化)

    线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayor ...

  5. D - Mayor's posters(线段树+离散化)

    题目: The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campai ...

  6. 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)

    [POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...

  7. Mayor's posters (线段树+离散化)

    Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...

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

    Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...

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

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

  10. [UESTC1059]秋实大哥与小朋友(线段树, 离散化)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1059 普通线段树+离散化,关键是……离散化后建树和查询都要按照基本法!!!RE了不知道多少次………………我真 ...

随机推荐

  1. linux命令补全 忘记命令只记得开头

    linux的shell不仅提供上下箭头来翻阅历史使用过的命令,还提供命令补全功能. 例如,你想创建一个文件夹,只记得是m开头的命令,此时可以: ①输入m ②按键盘上的Tab键两次 (有可能还出现这句话 ...

  2. C语言 结构体的内存对齐问题与位域

    http://blog.csdn.net/xing_hao/article/details/6678048 一.内存对齐 许多计算机系统对基本类型数据在内存中存放的位置有限制,它们会要求这些数据的首地 ...

  3. DVB系统中PCR的生成和PCR校正

    http://blog.csdn.net/chenliangming/article/details/3616720 引自<广播电视信息>2008年1月 从数字电视前端系统功能上来讲,传统 ...

  4. 转:Bitbucket使用方法

    一.软件及SSH keys: 由于我的Bitbucket账号的邮箱及用户名与Github相同,所以SSH Public Keys可以用Github的,登录Bitbucket,悬浮在用户名boliqua ...

  5. 怎样成为一名PHP专家?

    当浏览各类与PHP相关的博客时,比如Quora上的问题,谷歌群组,简讯和杂志,我经常注意到技能的等级分化.问题都类似于“我如何连接到MySQL数据库?”或者“我该如何扩展邮件系统才能在每小时发送超过一 ...

  6. 搜索插件:ack.vim

    ack.vim是Perl脚本ack的前端,对于Vim,也是grepprg和quickfix的简单封装,非常适合搜索 github地址为 https://github.com/mileszs/ack.v ...

  7. git设置忽略某些文件或文件夹

    在git中如果想忽略掉某个文件,不让这个文件提交到版本库中,可以使用修改 .gitignore 文件的方法.如果没有 .gitignore 文件,就自己创建一个,手动创建会提示你输入文件名称,因此,你 ...

  8. js模仿jquery里的几个方法next, pre, nextAll, preAll

    /*siblings函数, 选取node的所有兄弟节点*/ function siblings(node){ if(node.nodeType === 1){ node.flag = true; // ...

  9. poj 2635 The Embarrassed Cryptographer(数论)

    题目:http://poj.org/problem?id=2635 高精度求模  同余模定理. 题意: 给定一个大数K,K是两个大素数的乘积的值.再给定一个int内的数L 问这两个大素数中最小的一个是 ...

  10. usaco /the second wave

    bzoj4582:简单递推题. #include<cstdio> #include<cstring> #include<iostream> #include< ...