##【Codeforces】976C Nested Segments
【题目大意】
给你n个数对 ( l i , r i ) (l_i,r_i) (li,ri),让你找到一个i,j,使 l i < = l j l_i<=l_j li<=lj且 r i > = r j r_i>=r_j ri>=rj,输出任意答案。
【题解】
按照 l i l_i li排序,然后用一个量MAXN,存之前最大的 r i r_i ri,就可以了。
【代码如下】
#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
int n,M,id;
struct xcw{
int x,y,id;
bool operator <(const xcw b)const{return x<b.x||(x==b.x&&y>b.y);}
}a[300005];
int read(){
int ret=0;char ch=getchar();bool f=1;
for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');
for(; isdigit(ch);ch=getchar()) ret=(ret<<3)+(ret<<1)+ch-48;
return f?ret:-ret;
}
int main(){
// freopen("C.in","r",stdin);
// freopen("C.out","w",stdout);
n=read();
for(int i=1;i<=n;i++) a[i]=(xcw){read(),read(),i};
sort(a+1,a+1+n);M=a[1].y;id=1;
for(int i=2;i<=n;i++){
if(a[i].y<=M){printf("%d %d\n",a[i].id,a[id].id);return 0;}
if(M<a[i].y) M=a[i].y,id=i;
}
printf("-1 -1\n");
return 0;
}