线段树离散化hdu5124
来源:互联网 发布:保暖内衣选购知乎 编辑:程序博客网 时间:2024/04/29 23:57
Online JudgeOnline ExerciseOnline TeachingOnline ContestsExercise AuthorF.A.Q
Hand In Hand
Online Acmers
Forum | Discuss
Statistical ChartsBest Coder beta
VIP | STD Contests
Virtual Contests
DIY | Web-DIY beta
Recent Contests
Total Submission(s): 382 Accepted Submission(s): 187
Hand In Hand
Online Acmers
Forum | Discuss
Statistical ChartsBest Coder beta
VIP | STD Contests
Virtual Contests
DIY | Web-DIY beta
Recent Contests
lee
Mail 0(0)
Control Panel
Sign Out
Mail 0(0)
Control Panel
Sign Out
New~ 关于举办杭电程序设计竞赛(2014'12)的报名通知
【比赛提醒】BestCoder 你报名了吗?(点击报名)
【科普】什么是BestCoder?如何参加?
【比赛提醒】BestCoder 你报名了吗?(点击报名)
【科普】什么是BestCoder?如何参加?
lines
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 382 Accepted Submission(s): 187
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 integerN(1≤N≤105) ,indicating the number of lines.
Next N lines contains two integersXi and Yi(1≤Xi≤Yi≤109) ,describing a line.
Each test case begins with an integer
Next N lines contains two integers
Output
For each case, output an integer means how many lines cover A.
Sample Input
251 2 2 22 43 45 100051 12 23 34 45 5
Sample Output
31
Source
BestCoder Round #20
#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<vector>#include<cmath>#include<queue>#include<stack>#include<map>#include<set>#include<algorithm>using namespace std;const int maxn=100010;int X[maxn*2],N;struct node{ int x,y; node(){} node(int l,int r):x(l),y(r){}}line[maxn];struct IntervalTree{ int sum[maxn<<3],add[maxn<<3]; void build(int o,int l,int r) { sum[o]=add[o]=0; if(l==r)return; int mid=(l+r)>>1; build(o<<1,l,mid); build(o<<1|1,mid+1,r); } void pushdown(int o) { 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 pushup(int o) { sum[o]=max(sum[o<<1],sum[o<<1|1]); } void update(int o,int l,int r,int q1,int q2,int val) { if(q1<=l&&r<=q2) { add[o]+=val; sum[o]+=val; return ; } pushdown(o); int mid=(l+r)>>1; if(q1<=mid)update(o<<1,l,mid,q1,q2,val); if(q2>mid)update(o<<1|1,mid+1,r,q1,q2,val); pushup(o); } int query(int o,int l,int r,int q1,int q2) { if(q1<=l&&r<=q2)return sum[o]; pushdown(o); int mid=(l+r)>>1; int ans=0; if(q1<=mid)ans=max(ans,query(o<<1,l,mid,q1,q2)); if(q2>mid) ans=max(ans,query(o<<1|1,mid+1,r,q1,q2)); return ans; }}tree;int main(){ int T; scanf("%d",&T); while(T--) { scanf("%d",&N); int cnt=0; for(int i=1;i<=N;i++) { scanf("%d%d",&line[i].x,&line[i].y); X[cnt++]=line[i].x,X[cnt++]=line[i].y; } sort(X,X+cnt); cnt=unique(X,X+cnt)-X; tree.build(1,1,cnt); for(int i=1;i<=N;i++) { int l=lower_bound(X,X+cnt,line[i].x)-X+1; int r=lower_bound(X,X+cnt,line[i].y)-X+1; if(l<=r)tree.update(1,1,cnt,l,r,1); } printf("%d\n",tree.query(1,1,cnt,1,cnt)); } return 0;}
0 0
- 线段树离散化hdu5124
- HDU5124,线段树加离散化
- HDU5124 lines(离散)
- 线段树+离散化
- 离散化 + 线段树
- 线段树离散化
- 线段树离散化
- POJ_2528 线段树+离散化
- HDU3577 离散化+线段树
- poj2528 线段树+离散化
- poj2528线段树+离散化
- hdu4325线段树+离散化
- POJ2528 离散化线段树
- 【线段树+离散化】Cover
- poj2482 离散化+线段树
- poj2528_线段树+离散化
- poj1151(线段树+离散化)
- hdu3743(线段树+离散化)
- 取石子游戏详解NIM
- 开始刷oj吧
- 牛腩系统验证控件—RequiredFieldValidator & ValidationSummary
- 学习ART之生成Runtime OAT文件
- AFNetworking 新手入门
- 线段树离散化hdu5124
- Nginx编译安装错误error: the HTTP gzip module requires the zlib library
- 判断数组中是否包含重复数字
- js异步加载
- opencv 图像金字塔
- UML中的九种图(一)
- SSL协议概述和握手过程
- oc面向对象三大特性联系:点与圆
- ejs与undersore模板引擎冲突的解决方案