• CodeForces


    D. Case of Fugitive
    time limit per test
    3 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water.

    The only dry land there is an archipelago of n narrow islands located in a row. For more comfort let's represent them as non-intersecting segments on a straight line: island i has coordinates [li, ri], besides, ri < li + 1 for 1 ≤ i ≤ n - 1.

    To reach the goal, Andrewid needs to place a bridge between each pair of adjacent islands. A bridge of length a can be placed between the i-th and the (i + 1)-th islads, if there are such coordinates of x and y, that li ≤ x ≤ ri, li + 1 ≤ y ≤ ri + 1 and y - x = a.

    The detective was supplied with m bridges, each bridge can be used at most once. Help him determine whether the bridges he got are enough to connect each pair of adjacent islands.

    Input

    The first line contains integers n (2 ≤ n ≤ 2·105) and m (1 ≤ m ≤ 2·105) — the number of islands and bridges.

    Next n lines each contain two integers li and ri (1 ≤ li ≤ ri ≤ 1018) — the coordinates of the island endpoints.

    The last line contains m integer numbers a1, a2, ..., am (1 ≤ ai ≤ 1018) — the lengths of the bridges that Andrewid got.

    Output

    If it is impossible to place a bridge between each pair of adjacent islands in the required manner, print on a single line "No" (without the quotes), otherwise print in the first line "Yes" (without the quotes), and in the second line print n - 1 numbers b1, b2, ..., bn - 1, which mean that between islands i and i + 1 there must be used a bridge number bi.

    If there are multiple correct answers, print any of them. Note that in this problem it is necessary to print "Yes" and "No" in correct case.

    Examples
    Input
    4 4
    1 4
    7 8
    9 10
    12 14
    4 5 3 8
    Output
    Yes
    2 3 1
    Input
    2 2
    11 14
    17 18
    2 9
    Output
    No
    Input
    2 1
    1 1
    1000000000000000000 1000000000000000000
    999999999999999999
    Output
    Yes
    1
    Note

    In the first sample test you can, for example, place the second bridge between points 3 and 8, place the third bridge between points 7 and 10 and place the first bridge between points 10 and 14.

    In the second sample test the first bridge is too short and the second bridge is too long, so the solution doesn't exist.

    题意:n-1个区间 m个数

    数要满足的条件是大于等于左区间 小于等于又区间  问着m个数中有没有n-1个数满足这些区间(一个数不能重复满足多个区间)

    区间按左从小到大排序 用个优先队列维护区间右边的值 

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<string>
     5 #include<queue>
     6 #include<algorithm>
     7 #include<stack>
     8 #include<cstring>
     9 #include<vector>
    10 #include<list>
    11 #include<bitset>
    12 #include<set>
    13 #include<map>
    14 #include<time.h>
    15 using namespace std;
    16 typedef long long ll;
    17 typedef unsigned long long ull;
    18 const int N=500000+10;
    19 const int inf=0x3f3f3f3f;
    20 struct node{
    21     ll l,r;
    22     int pos;
    23     friend bool operator<(node aa,node bb){
    24         return aa.r>bb.r;
    25     }
    26 }a[N];
    27 struct Node{
    28     ll x;int pos;
    29 }b[N];
    30 bool cmp1(node aa,node bb){
    31     return aa.l<bb.l;
    32 }
    33 bool cmp2(Node aa,Node bb){
    34     return aa.x<bb.x;
    35 }
    36 priority_queue<node>q;
    37 int ans[N];
    38 int main(){
    39     int n,m;
    40     while(scanf("%d%d",&n,&m)!=EOF){
    41         ll l,r;
    42         scanf("%I64d%I64d",&l,&r);
    43         int t=0;
    44         ll x,y;
    45         for(int i=1;i<n;i++){
    46             scanf("%I64d%I64d",&x,&y);
    47             ll t1=x;
    48             ll t2=y;
    49             a[++t].l=x-r;
    50             a[t].r=y-l;
    51             a[t].pos=i;
    52             l=t1;r=t2;
    53         }
    54         sort(a+1,a+t+1,cmp1);
    55         for(int i=1;i<=m;i++){
    56             scanf("%I64d",&b[i].x);
    57             b[i].pos=i;
    58         }
    59         sort(b+1,b+1+m,cmp2);
    60         int k=1;
    61         int flag=0;
    62         int cnt=0;
    63         for(int i=1;i<=m;i++){
    64             x=b[i].x;
    65             for(int j=k;j<=t;j=k){
    66                 if(a[j].l<=x&&a[j].r>=x){
    67                     q.push(a[j]);k++;
    68                 }
    69                 else{
    70                     break;
    71                 }
    72             }
    73             if(q.empty())continue;
    74             node aa=q.top();q.pop();
    75             if(x>aa.r){
    76                 flag=1;
    77                 break;
    78             }
    79             cnt++;
    80             //cout<<cnt<<endl;
    81             ans[aa.pos]=b[i].pos;
    82         }
    83         if(cnt<t||flag){
    84             cout<<"No"<<endl;continue;
    85         }
    86         cout<<"Yes"<<endl;
    87         for(int i=1;i<=t;i++)cout<<ans[i]<<" ";
    88         cout<<endl;
    89     }
    90 }
  • 相关阅读:
    Go语言实现:【剑指offer】剪绳子
    delphi10.3安装使用mySQL
    uniGUI学习之把窗口分成左,右边(上下)三部分,并且在运行中可以动态调节其相对大小(36)
    uniGUI学习之UniStringGrid(35)
    uniGUI之主窗口折叠UI之UniTreeMenu(32-2)
    好网站
    ios图片
    ios启动图的相关问题
    自学php
    Parse error: syntax error, unexpected $end in diguoclassfunctions.php on line 1246
  • 原文地址:https://www.cnblogs.com/Aa1039510121/p/7696434.html
Copyright © 2020-2023  润新知