博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #248 (Div. 1) B. Nanami's Digital Board 暴力 前缀和
阅读量:7086 次
发布时间:2019-06-28

本文共 4589 字,大约阅读时间需要 15 分钟。

B. Nanami's Digital Board

题目连接:

Description

Nanami is an expert at playing games. This day, Nanami's good friend Hajime invited her to watch a game of baseball. Unwilling as she was, she followed him to the stadium. But Nanami had no interest in the game, so she looked around to see if there was something that might interest her. That's when she saw the digital board at one end of the stadium.

The digital board is n pixels in height and m pixels in width, every pixel is either light or dark. The pixels are described by its coordinate. The j-th pixel of the i-th line is pixel (i, j). The board displays messages by switching a combination of pixels to light, and the rest to dark. Nanami notices that the state of the pixels on the board changes from time to time. At certain times, certain pixels on the board may switch from light to dark, or from dark to light.

Nanami wonders, what is the area of the biggest light block such that a specific pixel is on its side. A light block is a sub-rectangle of the board, in which all pixels are light. Pixel (i, j) belongs to a side of sub-rectangle with (x1, y1) and (x2, y2) as its upper-left and lower-right vertex if and only if it satisfies the logical condition:

((i = x1 or i = x2) and (y1 ≤ j ≤ y2)) or ((j = y1 or j = y2) and (x1 ≤ i ≤ x2)).

Nanami has all the history of changing pixels, also she has some questions of the described type, can you answer them?

Input

The first line contains three space-separated integers n, m and q (1 ≤ n, m, q ≤ 1000) — the height and width of the digital board, and the number of operations.

Then follow n lines, each line containing m space-separated integers. The j-th integer of the i-th line is ai, j — the initial state of pixel (i, j).

If ai, j = 0, pixel (i, j) is initially dark.

If ai, j = 1, pixel (i, j) is initially light.
Then follow q lines, each line containing three space-separated integers op, x, and y (1 ≤ op ≤ 2; 1 ≤ x ≤ n; 1 ≤ y ≤ m), describing an operation.

If op = 1, the pixel at (x, y) changes its state (from light to dark or from dark to light).

If op = 2, Nanami queries the biggest light block with pixel (x, y) on its side.

Output

For each query, print a single line containing one integer — the answer to Nanami's query.

Sample Input

3 4 5

0 1 1 0
1 0 0 1
0 1 1 0
2 2 2
2 1 2
1 2 2
1 2 3
2 2 2

Sample Output

0

2
6

Hint

题意

给你一个01矩阵,然后有两个操作,1是将x y取反,2是问以x,y为边界的最大全1矩形的面积是多少

题解:

其实就是瞎暴力……

一看数据范围,只要能做到修改操作是o(n)和查询操作是o(n)的就好了

这个直接用单调栈那种思想,直接暴力去莽一波就好了

对于每一个格子维护四个值,l[x][y],r[x][y],u[x][y],d[x][y]表示这个格子最多往四个方向延展多少

代码

#include
using namespace std;const int maxn = 1005;int a[maxn][maxn],n,m,q,up[maxn][maxn],down[maxn][maxn],l[maxn][maxn],r[maxn][maxn];int x,y,op;void update(){ a[x][y]=1-a[x][y]; for(int j=1;j<=m;j++) if(a[x][j]) l[x][j]=l[x][j-1]+1; else l[x][j]=0; for(int j=m;j>=1;j--) if(a[x][j]) r[x][j]=r[x][j+1]+1; else r[x][j]=0; for(int i=1;i<=n;i++) if(a[i][y]) up[i][y]=up[i-1][y]+1; else up[i][y]=0; for(int i=n;i>=1;i--) if(a[i][y]) down[i][y]=down[i+1][y]+1; else down[i][y]=0;}void query(){ if(a[x][y]==0) { printf("0\n"); return; } int ans = 0; int U=1e9,D=1e9,L=1e9,R=1e9; for(int i=y;i>=1;i--) { U=min(U,up[x][i]); D=min(D,down[x][i]); ans=max(ans,(U+D-1)*(y-i+1)); } U=1e9,D=1e9,L=1e9,R=1e9; for(int i=y;i<=m;i++) { U=min(U,up[x][i]); D=min(D,down[x][i]); ans=max(ans,(U+D-1)*(i-y+1)); } U=1e9,D=1e9,L=1e9,R=1e9; for(int i=x;i>=1;i--) { L=min(L,l[i][y]); R=min(R,r[i][y]); ans=max(ans,(L+R-1)*(x-i+1)); } U=1e9,D=1e9,L=1e9,R=1e9; for(int i=x;i<=n;i++) { L=min(L,l[i][y]); R=min(R,r[i][y]); ans=max(ans,(L+R-1)*(i-x+1)); } printf("%d\n",ans);}int main(){ scanf("%d%d%d",&n,&m,&q); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&a[i][j]); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) if(a[i][j]) l[i][j]=l[i][j-1]+1; for(int j=m;j>=1;j--) if(a[i][j]) r[i][j]=r[i][j+1]+1; } for(int j=1;j<=m;j++) { for(int i=1;i<=n;i++) if(a[i][j]) up[i][j]=up[i-1][j]+1; for(int i=n;i>=1;i--) if(a[i][j]) down[i][j]=down[i+1][j]+1; } for(int i=1;i<=q;i++) { scanf("%d%d%d",&op,&x,&y); if(op==1)update(); else query(); }}

转载地址:http://zbgml.baihongyu.com/

你可能感兴趣的文章
Python爬虫学习之(一)| 从零开始
查看>>
专访msup创始人兼CEO刘付强:分享软件研发管理实践,在数据时代成为追求卓越的代名词...
查看>>
利器系列-更高效的Vim
查看>>
印象 · CNUTCon全球容器技术大会2016
查看>>
1.shell 脚本基础
查看>>
sql语言中join操作
查看>>
如何在 React 中做到 jQuery-free
查看>>
atom中最好的js代码片段
查看>>
新云主机的配置
查看>>
GraphQL 核心概念
查看>>
[译]Windows 下手动安装 Apache + PHP + MySQL
查看>>
小记Linux/UNIX下错误权限恢复
查看>>
http协议
查看>>
php的异常和处理
查看>>
# 天下武功无坚不破,唯快不破!
查看>>
Solus 4 发布,优雅现代的 Linux 发行版
查看>>
「镁客早报」苹果高通大战开庭;NASA为撞小行星任务选定承办方 ...
查看>>
Linux服务器---流量监控webalizer
查看>>
苹果自动驾驶项目大裁员;抖音再度回应微信无法登录;蔚来CEO李斌转让5000万股私人股份 | 雷锋早报 ...
查看>>
从边车模式到 Service Mesh
查看>>