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 ...
随机推荐
- Cognos邮件发送
1.打开报表,点击下图的标记 2.设置发送格式收件人 3.设置报表格式 4.设置发送内容
- cyclic swapping algorithm
原文见:https://leetcode.com/problems/couples-holding-hands/discuss/113362/JavaC%2B%2B-O(N)-solution-usi ...
- Django的架构
简介 Django继承并简化了MVC架构.MVC中的Controller部分基本全由Django完成.View部分被分割成两部分,即:负责HTML渲染的模板和负责显示逻辑的视图.所以Django又被称 ...
- VsCode使用之HTML 中 CSS Class 智能提示
HTML 中 CSS Class 智能提示 安装插件:HTML CSS Support 设置中添加以下代码: "editor.parameterHints": true, &quo ...
- tab bar controller
下面记一下怎样通过代码的方式为选项卡添加视图. 1.创建一个基于Empty Application的项目 2.创建两个新类,基类选择UIViewController,勾选With XIB for us ...
- vue的使用配置
我的编辑器是webstorm,虽然占内容占资源, 但是用起来很方便, 刚开始接触的时候就是用这个软件,很喜欢. vue的教程 1.http://www.jianshu.com/p/5ba253651c ...
- 大页(Huge Page)简单介绍
x86(包括x86-32和x86-64)架构的CPU默认使用4KB大小的内存页面(getconf PAGESIZE),但是它们也支持较大的内存页,如x86-64系统就支持2MB大小的大页(huge p ...
- Fiddler使用配置遇到的问题
针对Fiddler使用遇到的问题记录,方便后期再使用. 1.Chrome导入证书失败,提示"提示由于存储区只读的,存储区已满..." 方法:直接去控制台添加 详细参考:http:/ ...
- LeetCode 467. Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- 基本Sql语句汇总
关于Sql语句的学习,选择的DBMS为SQL Server,Sql语句随着工作中的应用不断补充,不具备系统性,为个人笔记汇总,网上有很多优秀的资源,故不对每一处应用做过多细致的说明,后期会对部分篇幅较 ...