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. 类似C语言格式化输出

    java se5引入的format方法可以用于PrintStream或PrintWriter对象,format方法模仿自C的printf(), 如果你比较怀旧的话,也可以用printf(). pack ...

  2. Vue 消息无缝滚动

    vue实现消息向上无缝滚动效果 <ul class="new-list" :class="{anim:animate}" @mouseenter=&quo ...

  3. BZOJ1576: [Usaco2009 Jan]安全路经Travel(树链剖分)

    Description Input * 第一行: 两个空格分开的数, N和M * 第2..M+1行: 三个空格分开的数a_i, b_i,和t_i Output * 第1..N-1行: 第i行包含一个数 ...

  4. BZOJ3277: 串(后缀自动机,Parent树,Dfs序)

    Description 字符串是oi界常考的问题.现在给定你n个字符串,询问每个字符串有多少子串(不包括空串)是所有n个字符串中 至少k个字符串的子串(注意包括本身). Input 第一行两个整数n, ...

  5. 设计模式六大原则(三):依赖倒置原则(Dependence Inversion Principle)

    依赖倒置原则(DIP)定义: 高层模块不应该依赖低层模块,二者都应该依赖其抽象:抽象不应该依赖细节:细节应该依赖抽象. 问题由来: 类A直接依赖类B,假如要将类A改为依赖类C,则必须通过修改类A的代码 ...

  6. Nodejs源代码分析之Path

    今天介绍一下nodejs Path的源代码分析,Path的API文档在https://nodejs.org/dist/latest-v5.x/docs/api/path.html,使用相对简单,在AP ...

  7. 【Oracle错误集锦】:PLSQL无法直连64位Oracle11g数据库

    背景:Oracle数据库装在本机上,使用PLSQL连接. 今天安装完Oracle 11g数据库后.用plsql连接数据库死活都连接不上.而且plsql客户端登录窗体的Database下拉框还为空.见下 ...

  8. 83.#pragma详解

    创建数据段 //创建数据段 #pragma data_seg("fangfangdata") ; #pragma data_seg() 与数据段连接,实现数据通信,分享 //实现数 ...

  9. Binary Search Algorithm

    二分查找代码: //============================================================================ // Name : Bin ...

  10. C# mongodb帮助类

    这是在C#连接MongoDB的帮助类,所使用的驱动是在Vs2015的Nuget管理器中下载的mongodb驱动. 下载第一个,会自动下载下面的两个,不要删除. 在配置文件中配置连接字符串connStr ...