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 ;
}

976 C. Nested Segments的更多相关文章

  1. ural1987 Nested Segments

    Nested Segments Time limit: 1.0 secondMemory limit: 64 MB You are given n segments on a straight lin ...

  2. Code Forces 652D Nested Segments(离散化+树状数组)

     Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  3. Educational Codeforces Round 10 D. Nested Segments 离线树状数组 离散化

    D. Nested Segments 题目连接: http://www.codeforces.com/contest/652/problem/D Description You are given n ...

  4. Educational Codeforces Round 10 D. Nested Segments 【树状数组区间更新 + 离散化 + stl】

    任意门:http://codeforces.com/contest/652/problem/D D. Nested Segments time limit per test 2 seconds mem ...

  5. codeforces 652D D. Nested Segments(离散化+sort+树状数组)

    题目链接: D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  6. Educational Codeforces Round 10 D. Nested Segments

    D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. D - Nested Segments CodeForces - 652D (离散化+树桩数组)

    D - Nested Segments CodeForces - 652D You are given n segments on a line. There are no ends of some ...

  8. [离散化+树状数组]CodeForces - 652D Nested Segments

    Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  9. Codeforces 976C Nested Segments

    题面: 传送门 C. Nested Segments Input file: standard input Output file: standard output Time limit: 2 secon ...

随机推荐

  1. 忽略PyCharm4中特定的警告提示信息

    有一种简单的方式忽略PyCharm4中的警告,光标放在下划线上,a. 等灯泡出现,点击灯泡或者b. 按下Alt和Enter键,选择'Ignore errors like this'. 或者,在设置里更 ...

  2. ubuntu上配tensorflow

    前一阵绕了大弯路,基本弄好了UEFI双系统后,面对的就是CUDA咋装在Linux. 好在教程好多,有些朋友建议先装CUDA再装显卡驱动.弄好之后记录一下详细过程吧. *** 这两天看了一些教程,还是感 ...

  3. Codeforces 988F. Rain and Umbrellas

    解题思路:动态规划 遍历点i,如果从前一个点i-1走到这个点i不需要伞,则疲劳值不变dp[i] = dp[i-1]. 如果前一个点i-1走到这一个点i需要伞,则从前面找一把伞. 即遍历前面的每个点j, ...

  4. C# AssemblyResolve事件可能不触发

    C# AssemblyResolve事件需要引用的dll的“复制本地”属性设置为False,如果为True,可能不会触发这个事件的处理函数. 我想设计一个自动加载分架构的C++/CLI的dll,用到了 ...

  5. windows py-faster-rcnn配置

    [原创帖!转载请注明] windows faster-rcnn安装一直会出现各种错误,本人在实验室电脑成功安装后,在自己电脑上同样的安装步骤也成功.所以做个总结,希望对大家有帮助. 一:安装环境 1. ...

  6. IPv6第二层寻址,IPv6接口要求

    1. IPv6第二层寻址 IPV6地址以两种方式与第2层地址相关.第一种方式是IPV6独有的,提供了从第2层地址构建接口ID的机制.第二种方式对IPv4和IPV6都是一样的,提供了将一个IP组播地址映 ...

  7. li自定义图标

    /*自定义list的图标*/ li{ list-style-image: url(../img/21.JPG); }

  8. 查看Linux 服务器是 32位还是64位的

    查看Linux 服务器是 32位还是64位的 getconf LONG_BIT 返回 64 代表就是 64位的: 返回 32 代表就是 32位的:

  9. java的selenium环境搭建

    1.下载jdk1.8   环境变量我的博客有我就不说                   selenium下载地址:http://npm.taobao.org/mirrors/selenium 2.下 ...

  10. redis数据库服务器开启的三种方式

    redis的启动方式1.直接启动  进入redis根目录,执行命令:  #加上‘&’号使redis以后台程序方式运行 1 ./redis-server & 2.通过指定配置文件启动  ...