Time Limit: 3s Memory Limit: 64MB

问题描述

Ljr has several lines. The lines are covered on the X axis. Let A is a point which is covered by the most lines. Ljr wants to know how many lines cover A.

输入描述

The first line contains a single integer T(1≤T≤100) (the data for N>100 less than 10 cases), indicating the number of test cases. Each test case begins with an integerN(1≤N≤〖10〗^5), indicating the number of lines. Next N lines contains two integers X_i and Y_i (-〖10〗^9≤X_i,Y_i≤〖10〗^9), describing a line.

输出描述

For each case, output an integer means how many lines cover A.

输入样例

2

5

1 2

2 3

2 4

3 4

5 1000

5

1 2

3 4

5 6

7 8

9 10

输出样例

3

1

?

【题目链接】:

【题解】



把区间端点离散化一下,然后就转换成区间最大值的问题了;

写个线段树就好;

x<=y不一定成立;



【完整代码】

#include <bits/stdc++.h>
#define rep1(i,a,b) for (int i = a;i <= b;i++)
using namespace std;
#define pb push_back; const int MAXN = 1e5+10; int ma[MAXN*2*4],tag[MAXN*2*4];
struct abc
{
int l,r;
}; abc aa[MAXN];
vector <int> a;
map <int,int> dic; void push_down(int rt)
{
tag[rt<<1]+=tag[rt];
tag[rt<<1|1]+=tag[rt];
ma[rt<<1]+=tag[rt];
ma[rt<<1|1]+=tag[rt];
tag[rt] = 0;
} void up_data(int L,int R,int l,int r,int rt)
{
//printf("%d %d\n",l,r);
if (L<=l && r <= R)
{
ma[rt]++;
tag[rt]++;
return;
}
if (tag[rt]!=0)
push_down(rt);
int m = (l+r)>>1;
if (L<=m)
up_data(L,R,l,m,rt<<1);
if (m<R)
up_data(L,R,m+1,r,rt<<1|1);
ma[rt] = max(ma[rt<<1],ma[rt<<1|1]);
} int main()
{
//freopen("D:\\rush.txt","r",stdin);
int T;
scanf("%d",&T);
while (T--)
{
memset(ma,0,sizeof(ma));
memset(tag,0,sizeof(tag));
dic.clear();
a.clear();
int n;
scanf("%d",&n);
rep1(i,1,n)
{
scanf("%d%d",&aa[i].l,&aa[i].r);
if (aa[i].l>aa[i].r)
swap(aa[i].l,aa[i].r);
if (!dic[aa[i].l])
{
a.push_back(aa[i].l);
dic[aa[i].l] = 1;
}
if (!dic[aa[i].r])
{
a.push_back(aa[i].r);
dic[aa[i].r] = 1;
}
}
sort(a.begin(),a.end());
rep1(i,1,n)
{
int l,r;
l = lower_bound(a.begin(),a.end(),aa[i].l)-a.begin()+1;
r = lower_bound(a.begin(),a.end(),aa[i].r)-a.begin()+1;
up_data(l,r,1,MAXN<<1,1);
} printf("%d\n",ma[1]);
}
return 0;
}

【C++竞赛 G】Lines的更多相关文章

  1. 江西财经大学第一届程序设计竞赛 G题 小Q的口袋校园

    链接:https://www.nowcoder.com/acm/contest/115/G来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  2. 湖南省第十二届大学生计算机程序设计竞赛 G Parenthesis

    1809: Parenthesis Description Bobo has a balanced parenthesis sequence P=p1 p2…pn of length n and q ...

  3. 桂林电子科技大学第三届ACM程序设计竞赛 G 路径

    链接:https://ac.nowcoder.com/acm/contest/558/G来源:牛客网 小猫在研究树. 小猫在研究路径. 给定一棵N个点的树,每条边有边权,请你求出最长的一条路径,满足经 ...

  4. 2018年湘潭大学程序设计竞赛G又见斐波那契

    链接:https://www.nowcoder.com/acm/contest/105/G来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  5. 牛客网 桂林电子科技大学第三届ACM程序设计竞赛 G.路径-带条件的树的直径变形-边权最大,边数偶数的树上的最长路径-树形dp

    链接:https://ac.nowcoder.com/acm/contest/558/G 来源:牛客网 路径 小猫在研究树. 小猫在研究路径. 给定一棵N个点的树,每条边有边权,请你求出最长的一条路径 ...

  6. 江西财经大学第一届程序设计竞赛 G

    链接:https://www.nowcoder.com/acm/contest/115/G来源:牛客网 题目描述 周末,小Q喜欢在PU口袋校园上参加各种活动刷绩点,体验丰富多彩的大学生活. 但是每个活 ...

  7. 2018年长沙理工大学第十三届程序设计竞赛 G 逃离迷宫 【BFS】

    链接:https://www.nowcoder.com/acm/contest/96/G 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  8. “景驰科技杯”2018年华南理工大学程序设计竞赛 G. Youhane as "Bang Riot"(斜率DP)

    题目链接:https://www.nowcoder.com/acm/contest/94/G 题意:中文题目,见链接 题解:设 sum[i] 为 a[i] 的前缀和,可得公式 dp[i] = min( ...

  9. 2018年湘潭大学程序设计竞赛G又见斐波那契(矩阵快速幂)

    题意 题目链接 Sol 直接矩阵快速幂 推出来的矩阵应该长这样 \begin{equation*}\begin{bmatrix}1&1&1&1&1&1\\1 & ...

随机推荐

  1. 2.3 Streams API 官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ 2.3 Streams API 2.3 Streams API 在0..0增加了一个 ...

  2. jQuery UI:邮箱自动补全函数

    $('#email').autocomplete({ delay:0, autoFocus:true, source:function(request,response){ var hosts = [ ...

  3. [ Eclipse ] [ Problem ] Eclipse 無法開啟問題

    因為 Eclipse 在設定環境的過程掛掉太多次,擷取一些網路上優秀的文章當作備份 http://www.ewdna.com/2013/12/Eclipse-Loading-Workbench.htm ...

  4. DG Cascade Standby

    SUMMARY 1. logical standby不支持cascading standby 2. 11.2.0.2之前版本cascading standby不支持RAC 3. 11.2.0.3之前版 ...

  5. Git提交.net项目的小问题

    今天早上写了点关于asp.net core授权的东西,输入git add .的时候出现的报错 $ git add .error: open(".vs/DOTNETAuthorization/ ...

  6. gerrit-申请id跟本地配置

    OpenID 是一个以用户为中心的数字身份识别框架,它具有开放.分散.自由等特性. 什么是gerrit? 看 了网上的介绍,感觉所谓的gerrit就是一个基于web实现代码管理的服务器.Gerrit ...

  7. wap.css

    wap.css 一.总结 1.官方有教程:英语的 http://www.developershome.com/wap/wcss/ 2.wap.css :就是控制页面在手机端样式的 3.DOCTYPE ...

  8. winform程序,备份数据库+并压缩+并删除以前的备份

    说明:为了定时备份服务器上的数据库并压缩到指定目录,方便下载到本地而写本程序.配合windows的任务计划,可以达到定时备份数据库的目的. 程序需引用SQLDMO.DLL,如电脑上已安装sqlserv ...

  9. html只能有一个id,并且id的值只能是一个

    1.如果有相同的ID,javascript只会取第一个具有该ID的标签. 2.如果id值有两个,JS只会取到第一个,并不会像class类一样,类名并列就可以同时取到.

  10. windows CE项目开发

    软件列表 1.Windows mobile 设备中心 2.Microsoft visual Studio 2008 3.串口调试工具(sscom42.exe) 4.Wince 6.0模拟器 5.vir ...