CF 480 E. Parking Lot
CF 480 E. Parking Lot
http://codeforces.com/contest/480/problem/E
题意:
给一个n*m的01矩阵,每次可以将一个0修改为1,求最大全0的矩阵。
分析:
将询问离线,从后往前处理询问,相当于每次将一个1变成0,答案是递增的。
用悬线法或者单调栈来求。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
#include<cctype>
#include<set>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ; char a[N][N];
int x[N], y[N], L[N], R[N], U[N][N], D[N][N], q1[N], q2[N], ans[N], sk[N];
int Ans, n, m; void solve() {
for (int i=; i<=n; ++i)
for (int j=; j<=m; ++j)
U[i][j] = a[i][j] == '.' ? U[i-][j] + : ;
for (int i=n; i>=; --i)
for (int j=; j<=m; ++j)
D[i][j] = a[i][j] == '.' ? D[i+][j] + : ;
for (int i=; i<=n; ++i) { // 单调栈
U[i][] = U[i][m+] = -;
for (int top=,j=; j<=m+; ++j) {
while (top > && U[i][j] < U[i][sk[top]]) R[sk[top]] = j, top--;
sk[++top] = j;
}
for (int top=,j=m; j>=; --j) {
while (top > && U[i][j] < U[i][sk[top]]) L[sk[top]] = j, top --;
sk[++top] = j;
}
for (int j=; j<=m; ++j)
Ans = max(Ans, min(U[i][j], R[j] - L[j] - ));
}
/*memset(R, 0x3f, sizeof(R)); // 悬线法
for (int i=1; i<=n; ++i) {
int last = 0;
for (int j=1; j<=m; ++j) {
if (a[i][j] == '.') L[j] = max(L[j], last + 1);
else last = j, L[j] = 0;
}
last = m + 1;
for (int j=m; j>=1; --j) {
if (a[i][j] == '.') R[j] = min(R[j], last - 1);
else last = j, R[j] = m + 1;
}
for (int j=1; j<=m; ++j)
Ans = max(Ans, min(U[i][j], R[j] - L[j] + 1));
}*/
}
bool update(int x,int k) { // 判断能否组成k*k的方阵
int L1 = , R1 = , L2 = , R2 = ;
for (int j=; j<=m; ++j) {
while (L1 <= R1 && j - q1[L1] + > k) L1 ++;
while (L1 <= R1 && U[x][q1[R1]] >= U[x][j]) R1 --;
q1[++R1] = j; while (L2 <= R2 && j - q2[L2] + > k) L2 ++;
while (L2 <= R2 && D[x][q2[R2]] >= D[x][j]) R2 --;
q2[++R2] = j; if (j >= k && U[x][q1[L1]] + D[x][q2[L2]] - >= k) {
Ans = k;
return true;
}
}
return false;
}
void Change(int x,int y) {
a[x][y] = '.';
for (int i=x; i<=n; ++i) U[i][y] = a[i][y] == '.' ? U[i-][y] + : ;
for (int i=x; i>=; --i) D[i][y] = a[i][y] == '.' ? D[i+][y] + : ;
}
int main() {
n = read(), m = read(); int Q = read();
for (int i=; i<=n; ++i) scanf("%s",a[i]+);
for (int i=; i<=Q; ++i) {
x[i] = read(),y[i] = read();
a[x[i]][y[i]] = 'X';
}
solve();
for (int i=Q; i>=; --i) {
ans[i] = Ans;
Change(x[i], y[i]);
while (update(x[i], Ans + ));
}
for (int i=; i<=Q; ++i) printf("%d\n",ans[i]);
return ;
}
CF 480 E. Parking Lot的更多相关文章
- Codeforces 480.E Parking Lot
E. Parking Lot time limit per test 3 seconds memory limit per test 256 megabytes input standard inpu ...
- 【26.8%】【CF 46D】Parking Lot
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- CF 480 B Long Jumps (map标记)
题目链接:http://codeforces.com/contest/480/problem/B 题目描述: Long Jumps Valery is a PE teacher at a ...
- CF数据结构练习
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
随机推荐
- servlet-api-2.5.jar - jar not loaded
由于包重复,把发布后的项目中的servlet-api-2.5.jar删除,不要clean项目,直接重新启动server即可.由于优先使用项目中的包,而实际使用需要tomcat中的包导致,直入页面会报o ...
- hdu-5475 An easy problem---线段树+取模
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5475 题目大意: 给X赋初值1,然后给Q个操作,每个操作对应一个整数M: 如果操作是1则将X乘以对应 ...
- BZOJ2431:[HAOI2009]逆序对数列(DP,差分)
Description 对于一个数列{ai},如果有i<j且ai>aj,那么我们称ai与aj为一对逆序对数.若对于任意一个由1~n自然数组成的 数列,可以很容易求出有多少个逆序对数.那么逆 ...
- luogu P3950 部落冲突
嘟嘟嘟 树剖板子题. #include<cstdio> #include<iostream> #include<algorithm> #include<cma ...
- Jmeter关于数据库的测试(mysql数据库)
建立jdbc链接:创建JDBC Connection Configuration. 添加——配置元件——JDBC Connection configuration: 配置JDBC Connection ...
- 从数据库中取出的数据,字段名为gb2312的 数据转码为utf8
$pj = Pj::find()->where($map)->asArray()->one(); if(!empty($pj)) { foreach ($pj as $k=>$ ...
- Git--将本地代码提交到服务器分支上
直接使用git push origin [branch-name],往往会出错,有可能本地版本比分支的版本更低 这个时候需要先将解决冲突,再将本地代码推送到服务器分支上 1. 在自己分支cs上提交代码 ...
- HDU 1273 漫步森林(数学 找规律)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1273 漫步森林 Time Limit: 2000/1000 MS (Java/Others) M ...
- Go 语言开始
尝试了LiteIDE碰到调试问题无法解决,只有换成了vscode. vscode有个问题, golang.org/x/ 这个包名下的包都下载不了,需要到 https://github.com/gola ...
- 过滤xss攻击脚本
<?php /** * @blog http://www.phpddt.com * @param $string * @param $low 安全别级低 */ function clean_xs ...