Parking Lot CodeForces - 480E
大意: 给定01矩阵, 单点赋值为1, 求最大全0正方形.
将询问倒序处理, 那么答案一定是递增的, 最多增长$O(n)$次, 对于每次操作暴力判断答案是否增长即可, 也就是说转化为判断是否存在一个边长$x$的正方形包含给定点, 可以维护左右两侧第一个1的位置, 从上往下滑动窗口即可$O(n)$判断, 总复杂度$O(n^2)$
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head const int N = 2e3+10;
int n, m, k, ans, Ans[N];
char s[N][N];
int dp[N][N], L[N][N], R[N][N], x[N], y[N];
void upd(int i) {
REP(j,1,m) if (s[i][j]=='.') L[i][j] = L[i][j-1]?L[i][j-1]:j;
PER(j,1,m) if (s[i][j]=='.') R[i][j] = R[i][j+1]?R[i][j+1]:j;
}
void DP() {
REP(i,1,n) REP(j,1,m) if (s[i][j]=='.') {
dp[i][j] = min({dp[i-1][j],dp[i][j-1],dp[i-1][j-1]})+1;
ans = max(ans,dp[i][j]);
}
REP(i,1,n) upd(i);
}
int chk(int U, int D, int y, int v) {
if (D-U+1<v) return 0;
deque<int> q1, q2;
REP(i,U,D) {
if (q1.size()&&i-q1[0]==v) q1.pop_front();
if (q2.size()&&i-q2[0]==v) q2.pop_front();
while (q1.size()&&L[i][y]>=L[q1.back()][y]) q1.pop_back();
while (q2.size()&&R[i][y]<=R[q2.back()][y]) q2.pop_back();
q1.push_back(i), q2.push_back(i);
if (i-U+1>=v&&R[q2[0]][y]-L[q1[0]][y]+1>=v) return 1;
}
return 0;
} int main() {
scanf("%d%d%d", &n, &m, &k);
REP(i,1,n) scanf("%s", s[i]+1);
REP(i,1,k) {
scanf("%d%d", x+i, y+i);
s[x[i]][y[i]] = 'X';
}
DP();
PER(i,1,k) {
Ans[i] = ans;
s[x[i]][y[i]] = '.', upd(x[i]);
int U = x[i], D = x[i];
while (s[U][y[i]]=='.') --U; ++U;
while (s[D][y[i]]=='.') ++D; --D;
while (chk(U,D,y[i],ans+1)) ++ans;
}
REP(i,1,k) printf("%d\n", Ans[i]);
}
Parking Lot CodeForces - 480E的更多相关文章
- ●CodeForces 480E Parking Lot
题链: http://codeforces.com/problemset/problem/480/E题解: 单调队列,逆向思维 (在线的话应该是分治做,但是好麻烦..) 离线操作,逆向考虑, 最后的状 ...
- Codeforces 46D Parking Lot
传送门 D. Parking Lot time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #135 (Div. 2) E. Parking Lot 线段数区间合并
E. Parking Lot time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces 219E Parking Lot 线段树
Parking Lot 线段树区间合并一下, 求当前要占的位置, 不包括两端点的写起来方便一点. #include<bits/stdc++.h> #define LL long long ...
- Codeforces 480.E Parking Lot
E. Parking Lot time limit per test 3 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces Parking Lot
http://codeforces.com/problemset/problem/630/I 简单的排列组合,推式子技巧:举一个小样例,看着推,别抽象着推,容易错 #include <iostr ...
- Codeforces Round#415 Div.2
A. Straight «A» 题面 Noora is a student of one famous high school. It's her final year in school - she ...
- CF 480 E. Parking Lot
CF 480 E. Parking Lot http://codeforces.com/contest/480/problem/E 题意: 给一个n*m的01矩阵,每次可以将一个0修改为1,求最大全0 ...
- Codeforces Round #127 (Div. 1) B. Guess That Car! 扫描线
B. Guess That Car! 题目连接: http://codeforces.com/contest/201/problem/B Description A widely known amon ...
随机推荐
- Trim Galore用法及参数考量
Trim Galore是一个非常流行的用于「去接头序列」的软件,用于处理高通量测序得到的原始数据.通常我们从测序公司拿到数据后,第一步就是评估数据的质量以及对raw data去接头处理.公司拿来的数据 ...
- IQR(Inter-Quartile Range)
IQR(Inter-Quartile Range)在统计中叫内距.内距又称为四分位差.具体如下:内距IQR即Inter-Quartile Range, 这是统计技术上的名词.内距又称为四分位差,是两个 ...
- P4390 [BOI2007]Mokia 摩基亚(cdq分治)
一样是cdq的板子 照着园丁的烦恼就好了 代码 #include <cstdio> #include <cstring> #include <algorithm> ...
- 题解——loj6278 数列分块入门2 (分块)
查询小于k的值 注意lower_bound一定要减去查找的起始位置得到正确的位置 调了快两天 淦 #include <cstdio> #include <algorithm> ...
- 分布式强化学习基础概念(Distributional RL )
分布式强化学习基础概念(Distributional RL) from: https://mtomassoli.github.io/2017/12/08/distributional_rl/ 1. Q ...
- Hbase与Oracle比较(列式数据库与行式数据库)
Hbase与Oracle比较(列式数据库与行式数据库) 1 主要区别 Hbase适合大量插入同时又有读的情况 Hbase的瓶颈是硬盘传输速度,Oracle的瓶颈是硬盘寻道时间. Hbase本质上只 ...
- ComponentOne使用技巧——从Winform穿越到WPF
概述 WPF 和 Winform 是两个单独的平台,但二者又都是基于 .NET 4.0 以上版本开发的,所以很多.NET开发人员就开始研究如何在WPF中使用Winform.微软已经架设了两个开发平台的 ...
- HDU 5754 Life Winner Bo(各类博弈大杂合)
http://acm.hdu.edu.cn/showproblem.php?pid=5754 题意: 给一个国际象棋的棋盘,起点为(1,1),终点为(n,m),现在每个棋子只能往右下方走,并且有4种不 ...
- latex建立参考文献的超链接
在Latex生成的pdf文档中建立超链接(如从正文到参考文献,从目录到相应内容,从页码编号到实际页面等),有利于读者快速定位当前阅读的信息. 如何在生成的pdf文件中包含超链接呢?需要注意一下两点: ...
- 【转】Windows Live Writer 代码插件改造
源码和插件都在后面,如果不想看我神神叨叨的可以直接到文章后面下载 一 .找插件 在使用Windows Live Writer 经常要用到插入代码的功能,根据博客园中教程,分别使用了: WindowsL ...