大意: 给定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的更多相关文章

  1. ●CodeForces 480E Parking Lot

    题链: http://codeforces.com/problemset/problem/480/E题解: 单调队列,逆向思维 (在线的话应该是分治做,但是好麻烦..) 离线操作,逆向考虑, 最后的状 ...

  2. Codeforces 46D Parking Lot

    传送门 D. Parking Lot time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. 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 ...

  4. Codeforces 219E Parking Lot 线段树

    Parking Lot 线段树区间合并一下, 求当前要占的位置, 不包括两端点的写起来方便一点. #include<bits/stdc++.h> #define LL long long ...

  5. Codeforces 480.E Parking Lot

    E. Parking Lot time limit per test 3 seconds memory limit per test 256 megabytes input standard inpu ...

  6. Codeforces Parking Lot

    http://codeforces.com/problemset/problem/630/I 简单的排列组合,推式子技巧:举一个小样例,看着推,别抽象着推,容易错 #include <iostr ...

  7. 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 ...

  8. CF 480 E. Parking Lot

    CF 480 E. Parking Lot http://codeforces.com/contest/480/problem/E 题意: 给一个n*m的01矩阵,每次可以将一个0修改为1,求最大全0 ...

  9. 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 ...

随机推荐

  1. vim使用跳转列表 jumps 来跟踪 (历史位置的)导航

    参考: Vim使用跳转列表来跟踪你的导航,你可以通过这个列表来向前或者向后导航. 跳转列表保留所有地方的轨迹,它可以跟踪文件名.行号和列号. 查看调整列表::jumps 导航键 描述 CTRL-o 跳 ...

  2. 大数乘法|2012年蓝桥杯B组题解析第六题-fishers

    (9')大数乘法 对于32位字长的机器,大约超过20亿,用int类型就无法表示了,我们可以选择int64类型,但无论怎样扩展,固定的整数类型总是有表达的极限!如果对超级大整数进行精确运算呢?一个简单的 ...

  3. [LightOJ 1341] Aladdin and the Flying Carpet (算数基本定理(唯一分解定理))

    题目链接: https://vjudge.net/problem/LightOJ-1341 题目描述: 问有几种边长为整数的矩形面积等于a,且矩形的短边不小于b 算数基本定理的知识点:https:// ...

  4. PHP feof()函数

    feof()函数检查是否已经到达文件末尾(EOF) EOF == end  of  file 如果出错或者文件指针到了文件末尾(EOF)则返回true,否则返回false 语法: feof(file) ...

  5. Java 基础功底

    Java 基础语法特性: 首先了解并做好Java Web 开发环境配置(包含 JDK 的配置)是非常必要的.其中 CLASSPATH 的值开始必须包含 ".",否则用 javac ...

  6. Unicode转字符串

    /// <summary> /// Unicode转字符串 /// </summary> /// <returns>The to string.</retur ...

  7. vue 父组件调用子组件方法

    情景: 父组件中引入上传附件的子组件:点击组件可以分别上传对应要求的图片,子组件内部循环可创建多个模块. 父组件传入数组子组件循环来创建不同的组件模块,所有事件都在子组件内部. 父组件页面的上方同时有 ...

  8. Scrapy基本命令

    全局命令,不用在项目中运行fetch:爬取网页,不依赖爬虫项目直接爬网页信息,并显示爬取过程scrapy命令格式:scrapy 命令名 --参数,可能通过--控制,例如:scrapy fetch -h ...

  9. docker-compose在dockerfile更新后自动更新image

    比如在dockerfile里需要新安装包 形如 加一行 RUN pip3 install XXX 之后,希望docker-compose能更新镜像, 然后启动容器 只需要启动时使用 --build即可 ...

  10. Lua面向对象之一:简单例子

    1.Lua面向对象实现步骤 ①创建一个全局表(称之为元表) ②设置这个元表的__index值(值通常为元表自己,这样就能通过__index查找到对应的属性和方法) __index 赋值其实是一个fun ...