先对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. CSData

    NSString 转换成NSData 对象 NSData* xmlData = [@"testdata" dataUsingEncoding:NSUTF8StringEncodin ...

  2. java nio 读取大文件

    package com.yao.bigfile; import java.io.File; import java.io.IOException; import java.io.RandomAcces ...

  3. H5拖拽事件的完整过程和语法

    <!DOCTYPE HTML> <html> <head> <style type="text/css"> #div1 { widt ...

  4. 洛谷 P1910 L国的战斗之间谍(水题日常)

    题目背景 L国即将与I国发动战争!! 题目描述 俗话说的好:“知己知彼,百战不殆”.L国的指挥官想派出间谍前往I国,于是,选人工作就落到了你身上. 你现在有N个人选,每个人都有这样一些数据:A(能得到 ...

  5. Vue踩坑第一步,安装Vue最新版本

    学习vue第一步肯定是安装vue-cli,那么肯定想去搜下如何安装vue-cli呢? 网上搜到的结果大都是: npm i vue-cli -g 输入vue -V发现: 输入node -v发现: 自己明 ...

  6. 深入Docker 存储驱动 (转)

    参考: http://static.dockerone.com/ppt/filedriver.html#28

  7. (转)SpringMVC学习(七)——Controller类的方法返回值

    http://blog.csdn.net/yerenyuan_pku/article/details/72511844 本文所有案例代码的编写均建立在前文SpringMVC学习(六)——SpringM ...

  8. nginx的编译安装

    下载源码 wget http://nginx.org/download/nginx-1.15.9.tar.gz 安装开发包组 yum groupinstall "Development To ...

  9. C-基础:数组名与取地址符&

    指出下面代码的输出,并解释为什么.(不错,对地址掌握的深入挖潜) main() { ]={,,,,}; ); printf(),*(ptr-)); } 输出:2,5     *(a+1)就是a[1], ...

  10. activiti工作流学习链接

    首页: http://www.activiti.org/书籍: activiti in action  入门demo: kft-activiti-demo   http://www.oschina.n ...