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. Objective-C基础笔记(9)Foundation常用类NSArray

    NSArray用来存储对象的有序列表,它是不可变的 NSArray不能存储C语言中的基本数据类型,如int.float.enum.struct,也不能存储nil,nil代表数组元素的结束 // // ...

  2. STM32 之ADC单次转换模式和连续转换模式

    一.背景 在STM32中的AD的单通道采样中可以设置成单次转换模式和连续转换模式,如何理解这两个转换模式的区别,通过程序又是怎样实现的? 二.正文 首先理解单次转换模式,即ADC进行单次转换(单样本) ...

  3. 2018/8/21 qbxt测试

    2018/8/21 qbxt测试 期望得分:0? 实际得分:0 思路:manacher   会写模板但是不会用 qwq 听了某人的鬼话,直接输出0,然后就gg了 #include <cstdio ...

  4. System and method for controlling switching between VMM and VM using enabling value of VMM timer indicator and VMM timer value having a specified time

    In one embodiment, a method includes transitioning control to a virtual machine (VM) from a virtual ...

  5. Vijos——T 1629 八

    https://vijos.org/p/1629 描述 八是个很有趣的数字啊.八=发,八八=爸爸,88=拜拜.当然最有趣的还是8用二进制表示是1000.怎么样,有趣吧.当然题目和这些都没有关系. 某个 ...

  6. D3.js中对array的使用

    由于D3类库和array密切相关,我们有必要讨论一下D3中的数据绑定以及在数组内部运算的方法. 1.D3中的数组 和其他编程语言一样,D3的数组元素可以是数字或者字符等类型,例如: someData= ...

  7. 2lession-文件访问

    今天继续学习python,因为是根据网上的教程,里面用到了一些例子,包含有后面的知识点.但是,因为自己稍微有点c.java等语言基础,所以并没有严格按照教程来学习,反而是遇到知识点就记录下来. 代码如 ...

  8. ORACLE10g R2【单实例 FS→单实例FS】

    ORACLE10g R2[单实例FS→单实例FS] 本演示案例所用环境:   primary standby OS Hostname pry std OS Version RHEL5.8 RHEL5. ...

  9. SD卡与tf卡引脚转换

    https://www.cnblogs.com/shangdawei/p/3255414.html

  10. c++ 常识

    1)  功能:格式化字符串输出    说明:format指定输出格式,后面跟要输出的变量        目前printf支持以下格式:          %c        单个字符          ...