ARC063F すぬけ君の塗り絵 2 / Snuke's Coloring 2
题面
一句话题面:给你一些点,求这些点之中夹的最大的矩形周长。(考虑边界)
Solution
首先是一个结论,答案矩形一定经过\(x=\frac{w}{2}\)或经过\(y=\frac{h}{2}\),不然答案一定不优.
怎么说?因为答案一定\(\ge 2*max(h,w)+1\),这个可以通过左右|上下显然得出.
接下来我们考虑扫描线,对于从左往右的\(p_i.x\),令\(p_i.x\)为右边界,单调栈维护上下边界然后左边界直接每一次-就行了.
唯一的问题在于弹栈时的一些小操作,代码中都有注释.
Code
/*
mail: mleautomaton@foxmail.com
author: MLEAutoMaton
This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define int ll
inline int gi(){
int f=1,sum=0;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
return f*sum;
}
const int N=2000010;
int w,h,n;
struct node{
int x,y;
bool operator<(const node &b)const{return x<b.x || (x==b.x && y<b.y);}
}p[N];
typedef pair<int,int> pii;
#define mp make_pair
pii a[N],b[N];//stack
int mx[N],tag[N],ans;
void pushup(int o){mx[o]=max(mx[o<<1],mx[o<<1|1]);}
void pushdown(int o){
if(!tag[o])return;
tag[o<<1]+=tag[o];tag[o<<1|1]+=tag[o];
mx[o<<1]+=tag[o];mx[o<<1|1]+=tag[o];
tag[o]=0;
}
void modify(int o,int l,int r,int posl,int posr,int v){
if(posl<=l && r<=posr){tag[o]+=v;mx[o]+=v;return;}
pushdown(o);int mid=(l+r)>>1;
if(posl<=mid)modify(o<<1,l,mid,posl,posr,v);
if(mid<posr)modify(o<<1|1,mid+1,r,posl,posr,v);
pushup(o);
}
void work(){
memset(mx,0,sizeof(mx));memset(tag,0,sizeof(tag));
sort(p+1,p+n+1);int l=0,r=0;
for(int i=1;i<n;i++){
if(p[i].y<=h/2){
//单调栈维护
int lst=i-1;
while(l && p[i].y>a[l].second){
modify(1,1,n,a[l].first,lst,a[l].second-p[i].y);
lst=a[l--].first-1;
}
if(lst!=i-1)
a[++l]=mp(lst+1,p[i].y);
}
else{
//单调栈维护
int lst=i-1;
while(l && p[i].y<b[r].second){
modify(1,1,n,b[r].first,lst,p[i].y-b[r].second);
lst=b[r--].first-1;
}
if(lst!=i-1)b[++r]=mp(lst+1,p[i].y);
}
modify(1,1,n,i,i,h-p[i].x);//为了便于计算答案.
a[++l]=mp(i,0);b[++r]=mp(i,h);//为了减去上面或者下面.
ans=max(ans,mx[1]+p[i+1].x);//计算答案.
}
}
signed main(){
w=gi();h=gi();n=gi();
for(int i=1;i<=n;i++)p[i].x=gi(),p[i].y=gi();
p[++n]=(node){0,0};p[++n]=(node){w,h};
work();
for(int i=1;i<=n;i++)swap(p[i].x,p[i].y);swap(h,w);
work();
printf("%lld\n",ans*2);
return 0;
}
ARC063F すぬけ君の塗り絵 2 / Snuke's Coloring 2的更多相关文章
- すぬけ君の塗り絵 / Snuke's Coloring AtCoder - 2068 (思维,排序,贡献)
Problem Statement We have a grid with H rows and W columns. At first, all cells were painted white. ...
- [arc063]F.すぬけ君の塗り絵2
因为这题考虑可以观察一个性质,答案的下界为 \(2×(max(w,h)+1)\), 因为你至少可以空出一行或一列,因此这个矩形一定会经过 \(x=\frac{w}{2}\) 或 \(y=\frac{h ...
- [Arc063F] Snuke's Coloring 2
[Arc063F] Snuke's Coloring 2 题目大意 给你一个网格图,一些点上有标记,求边长最大空白矩形. 试题分析 专门卡\(\log^2 n\)系列. 首先由题意我们可以找到答案的下 ...
- [arc063F]Snuke's Coloring 2-[线段树+观察]
Description 传送门 Solution 我们先不考虑周长,只考虑长和宽. 依题意得答案下限为max(w+1,h+1),并且最后所得一定是个矩形(矩形内部无点). 好的,所以!!!答案一定会经 ...
- 【ARC 063F】Snuke's Coloring 2
Description There is a rectangle in the xy-plane, with its lower left corner at (0,0) and its upper ...
- [ARC061E]すぬけ君の地下鉄旅行 / Snuke's Subway Trip
题目大意:Snuke的城镇有地铁行驶,地铁线路图包括$N$个站点和$M$个地铁线.站点被从$1$到$N$的整数所标记,每条线路被一个公司所拥有,并且每个公司用彼此不同的整数来表示. 第$i$条线路($ ...
- Snuke's Coloring 2-1
There is a rectangle in the xy-plane, with its lower left corner at (0,0) and its upper right corner ...
- AtCoder Regular Contest 063 F : Snuke’s Coloring 2 (线段树 + 单调栈)
题意 小 \(\mathrm{C}\) 很喜欢二维染色问题,这天他拿来了一个 \(w × h\) 的二维平面 , 初始时均为白色 . 然后他在上面设置了 \(n\) 个关键点 \((X_i , Y_i ...
- 2018.09.22 atcoder Snuke's Coloring 2(线段树+单调栈)
传送门 就是给出一个矩形,上面有一些点,让你找出一个周长最大的矩形,满足没有一个点在矩形中. 这个题很有意思. 考虑到答案一定会穿过中线. 于是我们可以把点分到中线两边. 先想想暴力如何解决. 显然就 ...
随机推荐
- Java实现树的遍历以及打印(递归,非递归)
import java.util.LinkedList; import java.util.Stack; public class BinarySearchTree1<E extends Com ...
- day 06 预科
目录 if判断 if判断习题 for循环 for循环习题 微信机器人 if判断 # 一条狗朝你过来了,你会干吗? 判断: 如果狗是大长腿牵来的狗--->打招呼:如果是条疯狗,跑. # if:如果 ...
- python(写入excel操作-xlwt模块)
一.安装xlwt模块 pip install xlwt 二.excel写入操作 这种方式只能新增或者覆盖文件写入 import xlwt # 创建一个workbook 设置编码 workbook = ...
- Linux DHCP 中继
具体到一个公司的网络环境中,不可能只有一个VLAN,更不可能对每个VLAN都架设一个DHCP服务器,这时就要做一个DHCP的中继,使得DHCP的广播可以通过VLAN. 实验拓扑 三层交换机下面连接一台 ...
- 【异常(待解决)】org.apache.http.NoHttpResponseException: api.weixin.qq.com:443 failed to respond
一.记录下异常堆栈信息 -- ::-exec-] ERROR weixin.popular.client.LocalHttpClient - execute error org.apache.http ...
- Gradle 使用教程之 Task 详解
最近打算学习下 gradle 在 Android 中的使用,结果百度出来的文章都是介绍性文章,没啥干货.后来找到 gradle 官网教程,自己对着撸. Gradle 概述: Gradle 是一个基于 ...
- Linux CentOs下安装lnmp
1.下载源码包 以root目录为例: cd ~ # 下载安装包 wget http://nginx.org/download/nginx-1.17.2.tar.gz # nginx wget http ...
- 洛谷 P2921 在农场万圣节Trick or Treat on the Farm题解
题意翻译 题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N<=100,000)个牛棚隔间中留下的糖果,以此来庆祝美国秋天的万圣节. 由于牛棚不太大,FJ通过指定 ...
- BLE——协议层次结构
未完待续…… BLE协议 Bluetooth Application Applications GATT-Based Profiles/Services Bluetooth Core (Stack) ...
- mybatis配置打印sql
mybatis配置打印sql: <settings> <setting name="logImpl" value="STDOUT_LOGGING&quo ...