先对n个点分类,然后按题意要求构造,构造的时候判断这个点的右上方之前是否有点,判断可以用线段树来操作。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
const int maxn=+;
vector<int>g[*maxn],FX,FY;
int w[maxn];
struct X
{
int x,y,id;
}s[maxn],tmp[maxn];
int n,Max;
int segtree[*maxn];
bool cmp(const X&a,const X&b) {return a.x<b.x;}
void quary(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R) {Max=max(Max,segtree[rt]); return ;}
int m=(l+r)/;
if(L<=m) quary(L,R,l,m,*rt);
if(R>m) quary(L,R,m+,r,*rt+);
}
void update(int pos,int val,int l,int r,int rt)
{
if(l==r&&l==pos) { segtree[rt]=val; return; }
int m=(l+r)/;
if(pos<=m) update(pos,val,l,m,*rt);
else update(pos,val,m+,r,*rt+);
segtree[rt]=max(segtree[*rt],segtree[*rt+]);
}
int main()
{
scanf("%d",&n); FX.clear(); FY.clear();
for(int i=;i<=n;i++) scanf("%d%d",&s[i].x,&s[i].y);
for(int i=;i<=n;i++) scanf("%d",&w[i]);
sort(s+,s++n,cmp);
for(int i=;i<=n;i++) g[s[i].y-s[i].x+].push_back(i);
bool fail=; map<int,int>h; h.clear();
memset(segtree,-,sizeof segtree);
for(int i=;i<=n;i++)
{
if(h[w[i]]==g[w[i]+].size()) {fail=;break;}
int id=g[w[i]+][h[w[i]]];
Max=-; quary(s[id].x,,,,);
if(Max>=s[id].y){fail=;break;}
update(s[id].x,s[id].y,,,);
int tmpx=s[id].x,tmpy=s[id].y;
FX.push_back(tmpx); FY.push_back(tmpy); h[w[i]]++;
}
if(fail==)
{
printf("YES\n");
for(int i=;i<FX.size();i++) printf("%d %d\n",FX[i],FY[i]);
}
else printf("NO\n");
return ;
}

CodeForces 596C Wilbur and Points的更多相关文章

  1. Codeforces Round #331 (Div. 2)C. Wilbur and Points 贪心

    C. Wilbur and Points Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/ ...

  2. Codeforces Round #331 (Div. 2) C. Wilbur and Points

    C. Wilbur and Points time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  3. 【26.67%】【codeforces 596C】Wilbur and Points

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. Codeforces 596D Wilbur and Trees

    http://codeforces.com/contest/596/problem/D 题目大意: 有n棵树排成一排,高度都为h. 主人公要去砍树,每次等概率地随机选择没倒的树中最左边的树或者最右边的 ...

  5. Codeforces 295E Yaroslav and Points 线段树

    Yaroslav and Points 明明区间合并一下就好的东西, 为什么我会写得这么麻烦的方法啊啊啊. #include<bits/stdc++.h> #define LL long ...

  6. codeforces 851C Five Dimensional Points(鸽巢原理)

    http://codeforces.com/contest/851/problem/C 题意 - 给出 n 个五维空间的点 - 一个点a为 bad 的定义为 存在两点 b, c, 使的<ab, ...

  7. Codeforces 909 D. Colorful Points (模拟)

    题目链接: Colorful Points 题意: 给出一段字符串(长度最大为1e6),每次操作可以删除字符串中所有相邻字符与其不同的字符.例如:aabcaa 删除一次就变成了aa,就无法再删除了.题 ...

  8. 【CodeForces】576 C. Points on Plane

    [题目]C. Points on Plane [题意]给定坐标系中n个点的坐标(范围[0,10^6]),求一种 [ 连边形成链后总长度<=2.5*10^9 ] 的方案.n<=10^6. [ ...

  9. Codeforces Beta Round #19D(Points)线段树

    D. Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

随机推荐

  1. spring mvc 解决 Could not open ServletContext resource [/WEB-INF/dispatcher-servlet.xml] 异常

    org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document fro ...

  2. 初识Vivado

    Vivado 设计套件包括高度集成的设计环境和新一代从系统到 IC 级的工具,这些均建立在共享的可扩展数据模型和通用调试环境基础上.这也是一个基于 AMBA AXI4 互联规范.IP-XACT IP ...

  3. docker上配置nginx负载均衡

    采用ubuntu系统,docker安装自行百度 1.安装tomcat docker run -d -p : tomcat docker run -d -p : tomcat 安装两个实例,端口分别为8 ...

  4. postgres的强制类型转换与时间函数

    一.类型转换postgres的类型转换:通常::用来做类型转换,timestamp到date用的比较多select  now()::dateselect  now()::varchar 示例1:日期的 ...

  5. 植物大战僵尸游戏的开发(python)

    装备东西: 搭建好python环境, 四张图片,(背景图片,炮弹图片,僵尸图片,豌豆图片),就ok了  没有安装pygame的需要进行安装  pip install pygame 参考视频 # 植物大 ...

  6. AspNetCore容器化(Docker)部署(四) —— Jenkins自动化部署

    一.前言 (Jenkins.Docker.Git/Svn组建一套简单的自动化发布流程) 文章中用到的相关服务器角色 角色 环境 功能 开发机 Win10.Docker(Linux OS) 编码.调试 ...

  7. ç7—UIViewController

    UIViewController继承了UIResponder,而UIResponder继承了NSObject,UIViewController是所有视图控制器的父类. 在MVC模式中,UIViewCo ...

  8. java读取nc文件的问题,前端ajax 发送参数进行交互的实例

    1.问题背景: 需要解析nc文件的数据源,获取一个三维数据,并计算器开发值. java 后台处理: 定以一个实例来接收解析的数据并返回给前端. package cn.edu.shou.domain; ...

  9. node如何导出数据成为excel格式

    node的应用方式,导出数据 首先,你要把数据库连接上,把你要导的数据表写出来 安装模块 $ npm install sequelize $ npm install mysql $ npm insta ...

  10. JavaScript中通过原型添加方法,解决数据共享问题,节省内存空间

    涉及知识点:(1)原型的引入(2)构造函数.原型对象和实例对象之间的关系(3)__proto__和prototype的理解 直接举例:在自定义构造函数创建对象时,因为创建的对象使用的不是同一个方法,所 ...