zoukankan      html  css  js  c++  java
  • 976 C. Nested Segments

    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[300006];
    int n;
    int main()
    {
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&e[i].x,&e[i].y);
            e[i].z=i;
        }
        sort(e,e+n);
        for(int i=0;i<n-1;i++)
        {
            if(e[i].x<=e[i+1].x && e[i].y>=e[i+1].y)
            {
                printf("%d %d
    ",e[i+1].z+1,e[i].z+1);
                return 0;
            }
        }
        printf("-1 -1
    ");
        return 0;
    }
  • 相关阅读:
    【JZOJ6409】困难的图论
    学习LCT小结
    jzoj5432. 【NOIP2017提高A组集训10.28】三元组
    jzoj6367. 【NOIP2019模拟2019.9.25】工厂(factory)
    jzoj6366. 【NOIP2019模拟2019.9.25】化学(chem)
    jzoj5433. 【NOIP2017提高A组集训10.28】图
    学习拓展中国剩余定理小结
    jzoj6300. Count
    jzoj3736. 【NOI2014模拟7.11】数学题
    jzoj6276. 【noip提高组模拟1】树
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/8977281.html
Copyright © 2011-2022 走看看