Codeforces Round #310 (Div. 1) B. Case of Fugitive(set二分)

时间:2023-01-13 08:44:11
B. 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 ≤ rili + 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.

Sample test(s)
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.


#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二分)的更多相关文章

  1. Codeforces Round &num;310 &lpar;Div&period; 1&rpar; B&period; Case of Fugitive set

    B. Case of Fugitive Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/555/p ...

  2. 贪心&sol;思维题 Codeforces Round &num;310 &lpar;Div&period; 2&rpar; C&period; Case of Matryoshkas

    题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...

  3. 构造 Codeforces Round &num;310 &lpar;Div&period; 2&rpar; B&period; Case of Fake Numbers

    题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...

  4. 找规律&sol;贪心 Codeforces Round &num;310 &lpar;Div&period; 2&rpar; A&period; Case of the Zeros and Ones

    题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...

  5. Codeforces Round &num;310 &lpar;Div&period; 1&rpar; C&period; Case of Chocolate set

    C. Case of Chocolate Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/555/ ...

  6. Codeforces Round &num;310 &lpar;Div&period; 2&rpar; B&period; Case of Fake Numbers 水题

    B. Case of Fake Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  7. Codeforces Round &num;310 &lpar;Div&period; 2&rpar; A&period; 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 ...

  8. Codeforces Round &num;310 &lpar;Div&period; 1&rpar; A&period; Case of Matryoshkas 水题

    C. String Manipulation 1.0 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  9. Codeforces Round &num;310 &lpar;Div&period; 1&rpar; C&period; Case of Chocolate &lpar;线段树&rpar;

    题目地址:传送门 这题尽管是DIV1的C. . 可是挺简单的. .仅仅要用线段树分别维护一下横着和竖着的值就能够了,先离散化再维护. 每次查找最大的最小值<=tmp的点,能够直接在线段树里搜,也 ...

随机推荐

  1. 【JavaScript】内置对象Math

    Math是具有用于数学常数和函数的属性和方法一内置对象.不是函数对象. 描述编辑 不像其他的全局对象,Math不是一个构造函数.所有属性和方法Math都是静态的.你指的是常数pi为Math.PI你调用 ...

  2. Android L 使用ART能提高多少性能?

    点击打开链接 刚刚结束的 Google I/O 大会上,Android 下一代操作系统「L」带来不少惊喜.新系统运行更快.更省电. 然而开发者对这个新系统也有颇多疑问,比如新的运行模式 ART 对开发 ...

  3. poj1180

    斜率优化dp 据说这题朴素的O(n2)dp也可以A 没试过 朴素的dp不难想:f[i]=min(f[j]+sumtime[i]*sumcost[j+1,i]+c*sumcost[j+1,n]) 稍微解 ...

  4. 基于ip san的iscsi操作执行过程

    SAN它是storage area network(存储区域网络)速记,早期san光纤通道技术被用于.当迟到iscsi协议后出现,为了在这两者之间区分.它分IP SAN和FC SAN.FC SAN由于 ...

  5. Win10系统下的Tomcat7&period;0配置

    为什么不用更高版本的Tomcat呢?好几个老师都说7.0的版本最好用,所以就推荐用这个.安Tomcat之前,我电脑上装的是jdk 9,安装了好几次Apache都不能启动,日志显示的是"启动报 ...

  6. JAVA WEB开发环境与搭建

    一:jdk下载与安装 (1)官网下载地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-506665 ...

  7. &lpar;转&rpar;ThreadLocal-面试必问深度解析

    ThreadLocal是什么 ThreadLocal是一个本地线程副本变量工具类.主要用于将私有线程和该线程存放的副本对象做一个映射,各个线程之间的变量互不干扰,在高并发场景下,可以实现无状态的调用, ...

  8. oracle profile 概要文件

    Profile文件概述: Profile是Oracle安全策略的一个组成部分,当Oracle建立数据库时,会自动建立名称为Default的Profile文件. 创建用户的时候,如果没有指定profil ...

  9. Mysql数据库字符集问题

    修改mysql数据库的默认编码方式 修改my.ini文件 加上 default-character-set=gb2312 设定数据库字符集 alter database da_name default ...

  10. 一个比较典型的WMI查询

    Get-WmiObject win32_bios -ComputerName server1, server2 | Format-Table ` @{n='Hostname';e={$_.__serv ...