CodeForces 596C Wilbur and Points
先对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的更多相关文章
- 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/ ...
- 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 ...
- 【26.67%】【codeforces 596C】Wilbur and Points
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces 596D Wilbur and Trees
http://codeforces.com/contest/596/problem/D 题目大意: 有n棵树排成一排,高度都为h. 主人公要去砍树,每次等概率地随机选择没倒的树中最左边的树或者最右边的 ...
- Codeforces 295E Yaroslav and Points 线段树
Yaroslav and Points 明明区间合并一下就好的东西, 为什么我会写得这么麻烦的方法啊啊啊. #include<bits/stdc++.h> #define LL long ...
- codeforces 851C Five Dimensional Points(鸽巢原理)
http://codeforces.com/contest/851/problem/C 题意 - 给出 n 个五维空间的点 - 一个点a为 bad 的定义为 存在两点 b, c, 使的<ab, ...
- Codeforces 909 D. Colorful Points (模拟)
题目链接: Colorful Points 题意: 给出一段字符串(长度最大为1e6),每次操作可以删除字符串中所有相邻字符与其不同的字符.例如:aabcaa 删除一次就变成了aa,就无法再删除了.题 ...
- 【CodeForces】576 C. Points on Plane
[题目]C. Points on Plane [题意]给定坐标系中n个点的坐标(范围[0,10^6]),求一种 [ 连边形成链后总长度<=2.5*10^9 ] 的方案.n<=10^6. [ ...
- Codeforces Beta Round #19D(Points)线段树
D. Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
随机推荐
- 不能说的hidden
不能说的hidden 时光跑跑...路在脚下...晨光依在...----Vashon 1.所谓"时尚",本质上就是自己看不见自己的样子.好比我们在地球上,却感觉不到地球在动. 2. ...
- qt project settings被禁用解决方案
转载请注明出处:http://www.cnblogs.com/dachen408/p/7422707.html qt project settings被禁用点击不了: 解决方案:需要点击该项目(或者项 ...
- vue下axios和fetch跨域请求
1.在config的index.js下面进行常用跨域配置代码:proxyTable: { '/apis': { //使用"/api"来代替"http://xxxx.cn& ...
- 登录脚本重构Element
登录脚本重构Element package com.gubai.selenium; import org.openqa.selenium.By; import org.openqa.selenium. ...
- hdu 3232 Crossing Rivers 过河(数学期望)
题意:你在点A,目的地是点B,A和B的距离为D.中间隔了好多条河(所有河不会重叠),每条河有3个参数(P,L,V),其中P表示距离A点的长度,L表示河的长度,V表示河里的船的速度.假设每条河中仅有1条 ...
- 洛谷 P2319 [HNOI2006]超级英雄
题目描述 题目描述 现在电视台有一种节目叫做超级英雄,大概的流程就是每位选手到台上回答主持人的几个问题,然后根据回答问题的多少获得不同数目的奖品或奖金.主持人问题准备了若干道题目,只有当选手正确回答一 ...
- Halcon学习笔记2
图像预处理 一般来说,我们采集到的图像会有一些小黑点,小斑点,不平滑等因素会会影响我们后期的算法,此时就需要我们对其图片进行预处理. 下面是一些预处理基本算子: 1.消除噪声:mean_image/b ...
- CFBundleURLTypes URL scheme
https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Ar ...
- app支付宝授权登录获取用户信息
由后台进行地址的拼接(前台进行授权) // 生成授权的参数 String sign = ""; Long userId1 = SecurityUser.getUserId(); S ...
- 5 秒创建 k8s 集群[转]
据说 Google 的数据中心里运行着超过 20 亿个容器,而且 Google 十年前就开始使用容器技术. 最初,Google 开发了一个叫 Borg 的系统(现在命令为 Omega)来调度如此庞大数 ...