大意: 给定01矩阵, 单点赋值为1, 求最大全0正方形.

将询问倒序处理, 那么答案一定是递增的, 最多增长$O(n)$次, 对于每次操作暴力判断答案是否增长即可, 也就是说转化为判断是否存在一个边长$x$的正方形包含给定点, 可以维护左右两侧第一个1的位置, 从上往下滑动窗口即可$O(n)$判断, 总复杂度$O(n^2)$

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. #include <math.h>
  5. #include <set>
  6. #include <map>
  7. #include <queue>
  8. #include <string>
  9. #include <string.h>
  10. #include <bitset>
  11. #define REP(i,a,n) for(int i=a;i<=n;++i)
  12. #define PER(i,a,n) for(int i=n;i>=a;--i)
  13. #define hr putchar(10)
  14. #define pb push_back
  15. #define lc (o<<1)
  16. #define rc (lc|1)
  17. #define mid ((l+r)>>1)
  18. #define ls lc,l,mid
  19. #define rs rc,mid+1,r
  20. #define x first
  21. #define y second
  22. #define io std::ios::sync_with_stdio(false)
  23. #define endl '\n'
  24. #define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
  25. using namespace std;
  26. typedef long long ll;
  27. typedef pair<int,int> pii;
  28. const int P = 1e9+7, INF = 0x3f3f3f3f;
  29. ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
  30. 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;}
  31. ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
  32. //head
  33.  
  34. const int N = 2e3+10;
  35. int n, m, k, ans, Ans[N];
  36. char s[N][N];
  37. int dp[N][N], L[N][N], R[N][N], x[N], y[N];
  38. void upd(int i) {
  39. REP(j,1,m) if (s[i][j]=='.') L[i][j] = L[i][j-1]?L[i][j-1]:j;
  40. PER(j,1,m) if (s[i][j]=='.') R[i][j] = R[i][j+1]?R[i][j+1]:j;
  41. }
  42. void DP() {
  43. REP(i,1,n) REP(j,1,m) if (s[i][j]=='.') {
  44. dp[i][j] = min({dp[i-1][j],dp[i][j-1],dp[i-1][j-1]})+1;
  45. ans = max(ans,dp[i][j]);
  46. }
  47. REP(i,1,n) upd(i);
  48. }
  49. int chk(int U, int D, int y, int v) {
  50. if (D-U+1<v) return 0;
  51. deque<int> q1, q2;
  52. REP(i,U,D) {
  53. if (q1.size()&&i-q1[0]==v) q1.pop_front();
  54. if (q2.size()&&i-q2[0]==v) q2.pop_front();
  55. while (q1.size()&&L[i][y]>=L[q1.back()][y]) q1.pop_back();
  56. while (q2.size()&&R[i][y]<=R[q2.back()][y]) q2.pop_back();
  57. q1.push_back(i), q2.push_back(i);
  58. if (i-U+1>=v&&R[q2[0]][y]-L[q1[0]][y]+1>=v) return 1;
  59. }
  60. return 0;
  61. }
  62.  
  63. int main() {
  64. scanf("%d%d%d", &n, &m, &k);
  65. REP(i,1,n) scanf("%s", s[i]+1);
  66. REP(i,1,k) {
  67. scanf("%d%d", x+i, y+i);
  68. s[x[i]][y[i]] = 'X';
  69. }
  70. DP();
  71. PER(i,1,k) {
  72. Ans[i] = ans;
  73. s[x[i]][y[i]] = '.', upd(x[i]);
  74. int U = x[i], D = x[i];
  75. while (s[U][y[i]]=='.') --U; ++U;
  76. while (s[D][y[i]]=='.') ++D; --D;
  77. while (chk(U,D,y[i],ans+1)) ++ans;
  78. }
  79. REP(i,1,k) printf("%d\n", Ans[i]);
  80. }

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. Miller_Rabin整理笔记

    目录 问题 别的 正事 代码 问题 一个数到底是不是素数 别的 首先列一下我们可以求素数的东西 根号暴力求 \(O(nloglogn)\)的埃氏筛 \(O(n)\)的欧拉筛 还有我们要学习的Mille ...

  2. (转)Swagger2 & Postman工具使用

    (二期)7.swagger2与postman [课程七]swagge...tman.xmind0.3MB [课程七预习]sw...tman.xmind31.3KB 随着互联网技术的发展,现在的网站架构 ...

  3. oracle 之 连接查询

    where 连接 select * from a,b //使用的是笛卡尔乘积  显示 a.count*b.count 条数 select * from a,b where a.id=b.id 其实只是 ...

  4. Install and Compile MatConvNet: CNNs for MATLAB --- Deep Learning framework

    Install and Compile MatConvNet: CNNs for MATLAB --- Deep Learning framework 2017-04-18  10:19:35 If ...

  5. 转载:linux tar 解压命令总结

    把常用的tar解压命令总结下,当作备忘: tar -c: 建立压缩档案 -x:解压 -t:查看内容 -r:向压缩归档文件末尾追加文件 -u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其 ...

  6. 【转】myeclipse 自定义视图Customize Perspective 没有反应

    官网查了下,解释如下:   附上链接https://www.myeclipseide.com/PNphpBB2-viewtopic-t-30151.html,大概意思是按如下图所示步骤更新即可.读者可 ...

  7. python Exception中的raise、assert

    使用raise抛出异常 当程序出现错误,python会自动引发异常,也可以通过raise显式地引发异常.一旦执行了raise语句,raise后面的语句将不能执行. 演示raise用法. try: s ...

  8. mesh合并

    [风宇冲]Unity3D性能优化:DrawCall优化 (2013-03-05 15:39:27) 转载▼ 标签: it unity unity3d unity3d教程 分类: Unity3d之优化 ...

  9. 四: scrapy爬虫框架

    5.爬虫系列之scrapy框架   一 scrapy框架简介 1 介绍 (1) 什么是Scrapy? Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架,非常出名,非常强悍.所谓的框架 ...

  10. SpringBoot中加密com.github.ulisesbocchio

    Jasypt Spring Boot 为 Spring Boot 项目中的属性源(property sources)提供加密支持. 有三种方法可以在项目中集成 jasypt-spring-boot: ...