先对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. ubuntu下php安装目录说明

    php当前安装目录 /etc/php5/ apache2:   采用APACHE2HANDLER启动 cli:   采用命令启动 fpm php-fpm启动 fpm2     php-fpm多实例 m ...

  2. iOS开发之cell位置contentOffset的用法

    @property(nonatomic)         CGPoint                      contentOffset;                  // default ...

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

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

  4. 获取当前目录 文件输出html 网页查看

    @echo off setlocal set LISTFILE=list.html echo MAKING LISTFILE … (PLEASE WAIT) echo ^<!doctype ht ...

  5. java工作流activiti的步骤

    链接:activiti 表名称的解释 工作流从流程定义到创建一个流程实例完成执行步骤(省略bpmn的画法) 工作流的所有操作都是使用流程引擎来进行操作的,流程引擎只是存储流程的过程,而不存储具体的业务 ...

  6. Python3简明教程(十二)—— 模块

    在这节我们将要学习 Python 模块相关知识.包括模块的概念和导入方法,包的概念和使用,第三方模块的介绍,命令行参数的使用等. 模块 到目前为止,我们在 Python 解释器中写的所有代码都在我们退 ...

  7. TensorFlow低阶API(四)—— 图和会话

    简介 TensorFlow使用数据流图将计算表示为独立的指令之间的依赖关系.这可生成低级别的编程模型,在该模型中,您首先定义数据流图,然后创建TensorFlow会话,以便在一组本地和远程设备上运行图 ...

  8. react开启一个项目 webpack版本出错

    npx create-react-app my-app cd my-app npm start 在命令行里执行以上语句就可(前两天刚刚发现,最新版的react对webpack的版本要了新要求,大概是他 ...

  9. SQL Prompt 格式化SQL会自动插入分号的问题

    一.问题 安装新版SQL Prompt,格式化SQL都会自动在SQL末端插入分号 格式化前 格式化后 二.解决方法 选择SQL Prompt下的Options... 选择左侧的Format下Style ...

  10. nginx发布web网站

    修改/conf/nginx.conf配置文件 server { listen *:; # Listen server_name ""; # Don't worry if " ...