976 C. Nested Segments
2024-10-01 14:15:55
You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj.
Segment [l1, r1] lies within segment [l2, r2] iff l1 ≥ l2 and r1 ≤ r2.
Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Input
The first line contains one integer n (1 ≤ n ≤ 3·105) — the number of segments.
Each of the next n lines contains two integers li and ri (1 ≤ li ≤ ri ≤ 109) — the i-th segment.
Output
Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Examples
Input
Copy
5
1 10
2 9
3 9
2 3
2 9
Output
Copy
2 1
Input
Copy
3
1 5
2 6
6 20
Output
Copy
-1 -1
寻找是否存在一个段包含在另一个段里,输出段的编号
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) ((a,0,sizeof(a)))
typedef long long ll;
struct node
{
int x,y,z;
bool operator<(const node &a)
{
return a.x==x?a.y<y:a.x>x;
}
}e[];
int n;
int main()
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d%d",&e[i].x,&e[i].y);
e[i].z=i;
}
sort(e,e+n);
for(int i=;i<n-;i++)
{
if(e[i].x<=e[i+].x && e[i].y>=e[i+].y)
{
printf("%d %d\n",e[i+].z+,e[i].z+);
return ;
}
}
printf("-1 -1\n");
return ;
}
最新文章
- This month Calendar
- Android中ListView动态加载数据
- IHttpHandler防止图片链接被盗用
- Win10 UWP开发中的重复性静态UI绘制小技巧 2
- 认识与入门 Markdown,Markdown教程
- [Android Pro] ant 编译android工程
- javascript实现二分查找
- 中文web font技术及方案
- verilog 实现加法器
- php fpm start.sh
- Oracle SQL篇(四)group by 分组与分组的加强 rollup
- STM32本学习笔记EXTI(外部中断)
- 图解Javascript——变量对象和活动对象
- nopCommerce 3.9 大波浪系列 之 网页加载Widgets插件原理
- Java NIO 学习总结 学习手册
- 番外篇--Moddule Zero 版本管理与组织单位管理
- Hystrix-request cache(请求缓存)
- 使用ethtool显示硬件PHY信息
- antv g6
- 使用git创建与合并分支
热门文章
- 深入浅出Struts2
- m_Orchestrate learning system---二十、如何写代码不容易犯错
- nyoj--528--找球号(三)(位运算&;&;set)
- caffe中lenet_solver.prototxt配置文件注解
- 使用ffmpeg批量合并flv文件
- 新型查询系统impala
- Batch脚本获取日期SET YEAR=%date:~10,4%
- python的数据类型转换
- 优动漫PAINT-简单的树、叶教学
- 利用js自带函数 数组去重