2018.09.22 atcoder Snuke's Coloring 2(线段树+单调栈)
传送门
就是给出一个矩形,上面有一些点,让你找出一个周长最大的矩形,满足没有一个点在矩形中。
这个题很有意思。
考虑到答案一定会穿过中线。
于是我们可以把点分到中线两边。
先想想暴力如何解决。
显然就是枚举矩形的上下边的坐标然后求两边的最大宽度。
用单调栈搞一下这样的效率是O(n2)O(n^2)O(n2)的。
考虑继续优化。
干脆我们只枚举一条边,另外一条用线段树维护最值。
代码:
#include<bits/stdc++.h>
#define N 300005
#define lc (p<<1)
#define rc (p<<1|1)
#define mid (T[p].l+T[p].r>>1)
using namespace std;
int w,h,n,top1,top2,ans;
struct Pot{int x,y;}p[N];
struct Node{int l,r,mx,add;}T[N<<2];
struct node{int id,val;}stk1[N],stk2[N];
inline int max(int a,int b){return a>b?a:b;}
inline void pushnow(int p,int v){T[p].mx+=v,T[p].add+=v;}
inline void build(int p,int l,int r){
T[p].l=l,T[p].r=r,T[p].mx=T[p].add=0;
if(l==r)return;
build(lc,l,mid),build(rc,mid+1,r);
}
inline void update(int p,int ql,int qr,int v){
if(T[p].l>qr||T[p].r<ql)return;
if(ql<=T[p].l&&T[p].r<=qr)return pushnow(p,v);
if(T[p].add)pushnow(lc,T[p].add),pushnow(rc,T[p].add),T[p].add=0;
if(qr<=mid)update(lc,ql,qr,v);
else if(ql>mid)update(rc,ql,qr,v);
else update(lc,ql,mid,v),update(rc,mid+1,qr,v);
T[p].mx=max(T[lc].mx,T[rc].mx);
}
inline void swap(int&x,int&y){x^=y,y^=x,x^=y;}
inline bool cmp(Pot a,Pot b){return a.x<b.x;}
inline void solve(){
sort(p+1,p+n+1,cmp),build(1,1,n),top1=top2=0;
for(int i=1;i<=n;++i){
int las=i-1;
if(p[i].y<=h/2){
while(top1&&stk1[top1].val<p[i].y){
update(1,stk1[top1].id,las,stk1[top1].val-p[i].y);
las=stk1[top1--].id-1;
}
if(las!=i-1)stk1[++top1]=(node){las+1,p[i].y};
}
else{
while(top2&&stk2[top2].val>p[i].y){
update(1,stk2[top2].id,las,p[i].y-stk2[top2].val);
las=stk2[top2--].id-1;
}
if(las!=i-1)stk2[++top2]=(node){las+1,p[i].y};
}
stk1[++top1]=(node){i,0},stk2[++top2]=(node){i,h};
update(1,i,i,h-p[i].x),ans=max(ans,T[1].mx+p[i+1].x);
}
}
inline int read(){
int ans=0;
char ch=getchar();
while(!isdigit(ch))ch=getchar();
while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
return ans;
}
int main(){
w=read(),h=read(),n=read();
for(int i=1;i<=n;++i)p[i].x=read(),p[i].y=read();
p[++n]=(Pot){0,0},p[++n]=(Pot){w,h};
solve();
for(int i=1;i<=n;++i)swap(p[i].x,p[i].y);
swap(w,h);
solve();
cout<<ans*2;
return 0;
}
2018.09.22 atcoder Snuke's Coloring 2(线段树+单调栈)的更多相关文章
- AtCoder Regular Contest 063 F : Snuke’s Coloring 2 (线段树 + 单调栈)
题意 小 \(\mathrm{C}\) 很喜欢二维染色问题,这天他拿来了一个 \(w × h\) 的二维平面 , 初始时均为白色 . 然后他在上面设置了 \(n\) 个关键点 \((X_i , Y_i ...
- 2018.09.19 atcoder Snuke's Coloring(思维题)
传送门 谁能想到这道题会写这么久. 本来是一道很sb的题啊. 就是每次选一个点只会影响到周围的九个方格,随便1e9进制就可以hash了,但是我非要作死用stl写. 结果由于技术不够高超,一直调不出来. ...
- 2018.09.22 atcoder Integers on a Tree(构造)
传送门 先考虑什么时候不合法. 第一是考虑任意两个特殊点的权值的奇偶性是否满足条件. 第二是考虑每个点的取值范围是否合法. 如果上述条件都满足的话就可以随便构造出一组解. 代码: #include&l ...
- 2018.09.19 atcoder Snuke's Subway Trip(最短路)
传送门 就是一个另类最短路啊. 利用颜色判断当前节点的最小花费的前驱边中有没有跟当前的边颜色相同的. 如果有这条边费用为0,否则费用为1. 这样跑出来就能ac了. 代码: #include<bi ...
- 2018.08.22 hyc的xor/mex(线段树/01trie)
hyc的xor/mex 描述 NOIP2017就要来了,备战太累,不如做做hyc的新题? 找回自信吧! 一句话题意:n个数,m个操作 操作具体来讲分两步 1.读入x,把n个数全部xor上x 2.询问当 ...
- 2018.09.22 上海大学技术分享 - An Introduction To Go Programming Language
老实说笔者学习 Go 的时间并不长,积淀也不深厚,这次因缘巧合,同组的同事以前是上海大学的开源社区推动者之一,同时我们也抱着部分宣传公司和技术分享的意图,更进一步的,也是对所学做一个总结,所以拟定了这 ...
- 【arc073e】Ball Coloring(线段树,贪心)
[arc073e]Ball Coloring(线段树,贪心) 题面 AtCoder 洛谷 题解 大型翻车现场,菊队完美压中男神的模拟题 首先钦定全局最小值为红色,剩下的袋子按照其中较大值排序. 枚举前 ...
- 2018.07.03 HDU Rikka with Phi(线段树)
Rikka with Phi Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) P ...
- Atcoder E - Meaningful Mean(线段树+思维)
题目链接:http://arc075.contest.atcoder.jp/tasks/arc075_c 题意:问数组a有多少子区间平均值为k 题解:一开始考虑过dp,但是显然不可行,其实将每一个数都 ...
随机推荐
- eclipse中build path与Web Deployment Assembly的作用,区别
转自:https://blog.csdn.net/heart_mine/article/details/79402792 以下内容只为做个笔记记录已下,有问题可以留言,欢迎补充. 今天在eclipse ...
- linux 下常用部分命令
关机 (系统的关机.重启以及登出 ) shutdown -h now 关闭系统() init 关闭系统() shutdown -h hours:minutes & 按预定时间关闭系统 shut ...
- Annoying “Remote System Explorer Operation” causing freeze for couple of seconds
Eclipse -> Preferences -> General -> Startup and Shutdown. -Uncheck RSE UI. Eclipse -> P ...
- 使用sqldeveloper连接服务器端数据库
- AJAX是什么?
AJAX的全称是Asynchronous JavaScript and XML(异步的 JavaScript 和 XML). ajax不是新的编程语言,而是一种使用现有标准的新方法.ajax是与服务器 ...
- MVC控制器详解
原文地址:http://www.cnblogs.com/SeeYouBug/p/6441934.html#3628606 目录 一.理解控制器 1.1.什么是控制器 1.2.控制器的作用 1.3.创建 ...
- Hystrix-超时设置
由于客户端请求服务端方法时,服务端方法响应超过1秒将会触发降级,所以我们可以配置Hystrix默认的超时配置 如果我们没有配置默认的超时时间,Hystrix将取default_executionTim ...
- Python Env
简介: 记录 CentOS 6.x Python 环境的安装步骤. 一.安装依赖包 shell > yum -y install epel-release shell > yum -y i ...
- VC中使用ADO操作数据库的方法
源地址:http://blog.csdn.net/xiaobai1593/article/details/7459862 准备工作: (1).引入ADO类 #import "c:\progr ...
- node系列:全局与本地
查看:默认和当前的 全局与本地 全局路径:npm config get prefix 本地路径:npm config get cache 修改 修改就会创建对应目录(文件夹) 修改本地路径:npm c ...