Codeforces Round #310 (Div. 1) B. Case of Fugitive(set二分)
3 seconds
256 megabytes
standard input
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.
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.
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.
4 4
1 4
7 8
9 10
12 14
4 5 3 8
Yes
2 3 1
2 2
11 14
17 18
2 9
No
2 1
1 1
1000000000000000000 1000000000000000000
999999999999999999
Yes
1
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.
#include <bits/stdc++.h>
#define foreach(it,v) for(__typeof(v.begin()) it = v.begin(); it != v.end(); ++it)
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
#define x first
#define y second
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plll;
typedef plll Seg;
typedef pll Bridge;
bool cmpSeg(const Seg & a, const Seg & b)
{
pll ta = a.x, tb = b.x;
if(ta.y == tb.y) return ta.x < tb.x;
return ta.y < tb.y;
}
Seg p[maxn];
Bridge a[maxn];
ll l[maxn],r[maxn],ans[maxn];
int main(int argc, char const *argv[])
{
ios_base::sync_with_stdio(false);cin.tie(0);
int n,m;
while(cin>>n>>m) {
for(int i = 1; i <= n; i++) {
cin>>l[i]>>r[i];
}
for(int i = 1; i < n; i++) {
p[i-1].x.x = l[i+1] - r[i];
p[i-1].x.y = r[i+1] - l[i];
p[i-1].y = i-1;
}
sort(p,p+n-1,cmpSeg);
set<Bridge>Q;
for(int i = 1; i <= m; i++) {
ll a,id = i;cin>>a;
Q.insert(make_pair(a,id));
}
set<Bridge>::iterator it;
bool ok = (m + 1 >= n);
for(int i = 0; i < n-1; i++) {
if(!ok) break;
it = Q.lower_bound(make_pair(p[i].x.x,0LL));
if(it==Q.end()||it->x > p[i].x.y) {
ok = false;
break;
}
ans[p[i].y] = it->y;
Q.erase(it);
}
if(ok) {
cout<<"Yes\n";
for(int i = 0; i < n-1; i++)cout<<ans[i]<<" ";
cout<<"\n";
}else cout<<"No\n";
}
return 0;
}
Codeforces Round #310 (Div. 1) B. Case of Fugitive(set二分)的更多相关文章
- Codeforces Round #310 (Div. 1) B. Case of Fugitive set
B. Case of Fugitive Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/555/p ...
- 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...
- 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers
题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...
- 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones
题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...
- Codeforces Round #310 (Div. 1) C. Case of Chocolate set
C. Case of Chocolate Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/555/ ...
- Codeforces Round #310 (Div. 2) B. Case of Fake Numbers 水题
B. Case of Fake Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones 水题
A. Case of the Zeros and Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...
- Codeforces Round #310 (Div. 1) A. Case of Matryoshkas 水题
C. String Manipulation 1.0 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...
- Codeforces Round #310 (Div. 1) C. Case of Chocolate (线段树)
题目地址:传送门 这题尽管是DIV1的C. . 可是挺简单的. .仅仅要用线段树分别维护一下横着和竖着的值就能够了,先离散化再维护. 每次查找最大的最小值<=tmp的点,能够直接在线段树里搜,也 ...
随机推荐
- linux内核自锁旋spinlock常用宏解释
转自:http://blog.sina.com.cn/s/blog_6929134b0100tdn8.html 自旋锁与互斥锁有点类似,只是自旋锁不会引起调用者睡眠,如果自旋锁已经被别的执行单元保持, ...
- 代码实现Android5.0的下拉刷新效果
如图所示,实现类似与gmail的下拉刷新. 项目地址:https://github.com/stormzhang/SwipeRefreshLayoutDemo 一.在xml文件中定义 这个控件在sup ...
- SVG Stroke属性
一.stroke属性介绍 SVG提供了一个范围广泛stroke属性,用于描述轮廓,其中包括 stroke 指定颜色 stroke-width 指定宽度 stroke-linecap 指定端点样式 st ...
- Html、Asp、Php、Jsp禁止页面缓存
html:<meta http-equiv="pragma" content="no-cache"><meta http-equiv=&quo ...
- NOI 2015 Bless All!
明天day1,加油!RP++! (话说出题人貌似是dyf&lyd?好虚啊……
- QT中使用MinGW 编译的protobuf库--包含库的生成和使用
QT中使用MinGW 编译的protobuf库--包含库的生成和使用 0前言 1准备工作 2生成protobuf库文件 3在QT中测试protobuf的使用 4结语 0前言 最近要在QT中使用prot ...
- DEV控件之ChartControl 属性设置【转】
DEV控件之ChartControl用法 一.总体概述 这个控件包含3层,最外面的chartControl层.中间的XYDiagram层.最里面的Series层.功能非常强大,但同时使用起来也相对复杂 ...
- 会动的文字Marquee应用(转)
想要做个滚动公告,看了网上的教程,无一不是很恐怖的场频啊java语言编制的JS,或者就是各种复杂,无意中发现了Marquee这东西,用了一下,很简单,只需两行代码,即可以实现很好的效果,特此分享一下. ...
- android api doc 一
Manifest.permission 用于记录相应权限类 ACCESS_CHECKIN_PROPERTIES 允许在登入数据库的时候读写其中的属性表,并上传改变的值 ACCESS_COARSE_LO ...
- springboot下配置多数据源
摘自: http://blog.csdn.net/wangqingqi20005/article/details/52613055