The problem is obviously that it can be converted into this question:
There are n-1 intervals, m number,
Each number can only be used at most once, the number of number I can be included in the section J, then this can be placed in this interval.
Find out what happens when there is a number in all the intervals.
We sort all the intervals in ascending order of the lower bound, and then divide all the numbers in ascending order.
The process of division, maintenance of an element is a small heap of interval, the top of the heap is the lowest limit of the interval.
Consider the number of I, put all the bands that can contain it into the heap, and then throw an interval out of the heap, if the interval can contain this number, then record it, otherwise no solution, end the program.
Why is there no solution at this time? Because it is clear that the subsequent number is not less than this number, all subsequent numbers will not be included in this interval, then this interval cannot find the number that matches, so there is no solution.
Why should the minimum interval pop-up be given priority? Because in the case of a solution, for the number of I, all the intervals in the heap can contain this number, and the interval limit will be the number of J (J>i) included, so it is only necessary to consider the interval upper limit of this factor, consider the principle of greed, it is clear that the upper limit of the minimum interval is first disposed of.
#include <map> #include <string> #include <cstring> #include <cstdio> #include <cstdlib># include<cmath> #include <queue> #include <vector> #include <iostream> #include <algorithm > #include <bitset> #include <climits> #include <list> #include <iomanip> #include <stack > #include <set>using namespace std;typedef long long ll;struct island{ll l,r;int no;bool operator < (island one ) Const{return R>ONE.R;}} Island[int (2E5) +10];bool CMP (island One,island) {return ONE.L<TWO.L;} struct Bridge{ll len;int No;} Bridge[int (2e5) +10];bool cmp1 (Bridge one,bridge) {return one.len<two.len;} Priority_queue<island>qq;int ans[int (2e5) +10];int main () {int n,m;cin>>n>>m;ll pl,pr;for (int i=0;i <n;i++) {ll l,r;cin>>l>>r;if (i>0) {island[i-1].l=l-pr;island[i-1].r=r-pl;island[i-1].no=i-1;} Pl=l;pr=r;} Sort (island,island+n-1,cmp); for (int i=0;i<m;i++) {cin>>bridge[i].len;bridge[i].no=i;} Sort (bridge,bRIDGE+M,CMP1), int sum=0;for (int i=0,j=0;i<m;i++) {while (j<n-1&&island[j].l<=bridge[i].len& &BRIDGE[I].LEN<=ISLAND[J].R) Qq.push (island[j++]), if (Qq.empty ()) Continue;island t=qq.top (); Qq.pop (); if ( BRIDGE[I].LEN>T.R) {puts ("No"); return 0;} ans[t.no]=bridge[i].no;sum++;} if (sum<n-1) {puts ("No"); return 0;} Puts ("Yes"), for (int i=0;i<n-1;i++) {if (i) cout<< ""; cout<<ans[i]+1;}}
Time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard 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 are an archipelago ofNNarrow islands located in a row. For + comfort Let's represent them as non-intersecting segments on a straight Line:islandIhas coordinates[l,? RI], besides, Ri? <? L i? +?1 For1?≤? i? ≤? n?-? 1.
To reach the goal, Andrewid needs to place a bridge between each pair ofadjacentIslands. A Bridge of lengthaCan be placed between theI-th and the(i. +?1)-th Islads, if there is such coordinates ofxandy, that li? ≤? x? ≤? R I , li? +?1? ≤? y? ≤? R i? +?1 and y?-? x? =? a .
The detective is supplied with m bridges, and each bridge can is used at most once. Help him determine whether the bridges he got is enough to connect each pair of adjacent islands.
Input
The first line contains integersN(2?≤? n? ≤?2 105 ) andm(1?≤? m. ≤?2 105 )-the number of islands and bridges.
NextNLines each contain, integers li and Ri (1?≤? L i? ≤? R i. ≤?10 )-the coordinates of the island endpoints.
The last line containsmintegerNumbers a1,? a 2,?...,? a m (1?≤? a i. ≤?10 )-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?-? 1Numbers b1,? b 2,?...,? b n?-? 1 , which mean that between islandsIand i? +?1There must be used a bridge number bi .
If There is multiple correct answers, print any of them. Note that's this problem it's necessary to print "Yes" and "No" in the correct case.
Sample Test (s) input
4 41 47 89 1012 144 5 3 8
Output
Input
2 211 1417) 182 9
Output
No
Input
2 11 11000000000000000000 1000000000000000000999999999999999999
Output
Note
In the first sample test-can, for-example, place the second-bridge between points 3 and 8, place the third bridge BETW Een points 7 and place the first bridge between points and 14.
In the second sample test the first bridge was too short and the second bridge was too long, so the solution doesn ' t exist.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces 556 D Case of fugitive