B. Nanami's Digital Board

题目连接:

http://www.codeforces.com/contest/434/problem/B

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<bits/stdc++.h>
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();
}
}

Codeforces Round #248 (Div. 1) B. Nanami's Digital Board 暴力 前缀和的更多相关文章

  1. Codeforces Round #248 (Div. 1) D - Nanami's Power Plant 最小割

    D - Nanami's Power Plant 思路:类似与bzoj切糕那道题的模型.. #include<bits/stdc++.h> #define LL long long #de ...

  2. 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root

    题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...

  3. Codeforces Round #248 (Div. 2) (ABCD解决问题的方法)

    比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory ...

  4. Codeforces Round #248 (Div. 1)——Nanami&#39;s Digital Board

    题目连接 题意: 给n*m的0/1矩阵,q次操作,每次有两种:1)将x,y位置值翻转 2)计算以(x,y)为边界的矩形的面积最大值 (1 ≤ n, m, q ≤ 1000) 分析: 考虑以(x,y)为 ...

  5. Codeforces Round #248 (Div. 2) C. Ryouko's Memory Note

    题目链接:http://codeforces.com/contest/433/problem/C 思路:可以想到,要把某一个数字变成他的相邻中的数字的其中一个,这样总和才会减少,于是我们可以把每个数的 ...

  6. Codeforces Round #248 (Div. 2)C 题

    题目:http://codeforces.com/contest/433/problem/C 没想到做法就各种纠结, 今天做的都快疯掉了, 太弱了, 等题解一出,就各种恍然大悟 不应该不应该 正文: ...

  7. Codeforces Round #248 (Div. 1) A. Ryouko's Memory Note 水题

    A. Ryouko's Memory Note 题目连接: http://www.codeforces.com/contest/434/problem/A Description Ryouko is ...

  8. Codeforces Round #248 (Div. 2) B称号 【数据结构:树状数组】

    主题链接:http://codeforces.com/contest/433/problem/B 题目大意:给n(1 ≤ n ≤ 105)个数据(1 ≤ vi ≤ 109),当中有m(1 ≤ m ≤  ...

  9. Codeforces Round #248 (Div. 2) B. Kuriyama Mirai's Stones

    题目简单描述就是求数组中[l,r]区间的和 #include <iostream> #include <vector> #include <string> #inc ...

随机推荐

  1. jmeter,测登录,要不要过滤掉JS,CSS等请求?感觉过滤掉了压出来的数据就不真实?

    首先,我们来明确下你的性能测试目的,你的目的是服务端的性能还是前端的性能.这两用目的所涉及到的测试场景和工具等方法是不一样的.1.我们先来谈谈服务端的性能.一般的web产品,像css, jpeg等这种 ...

  2. MySQL GTID你知多少【转】

    MySQL在5.6的版本推出了GTID复制,相比传统的复制,GTID复制对于运维更加友好,这个事务是谁产⽣,产⽣多少事务,⾮常直接的标识出来,当然GTID也有限制,对于什么是GTID可以参考我之前的文 ...

  3. 虚拟环境pipenv的使用

    安装虚拟环境 安装python3.6 python -m site --user-base 找到 用户基础目录 指定python版本的方式 pipenv --python 3.8 安装 用户范围内安装 ...

  4. C#连接MySQL 操作步骤

    1.工具安装: 安装 MySQL For Windows,这个不多说,上官网下载: 安装mysql-connector-net,这个是MySQL数据库.NET开发驱动,因为C#是.NET架构的,所以需 ...

  5. c++语言知识点汇总

    c++ primer version-5 的整理 section 1: 内置类型和自定义类型: main函数的返回值:指示状态.0:成功:1:系统定义. unix和win系统中,执行完程序可以使用ec ...

  6. Focal Loss笔记

    论文:<Focal Loss for Dense Object Detection> Focal Loss 是何恺明设计的为了解决one-stage目标检测在训练阶段前景类和背景类极度不均 ...

  7. UFLDL(五)自编码算法与稀疏性

    新教程内容太繁复,有空再看看,这节看的还是老教程: http://ufldl.stanford.edu/wiki/index.php/%E8%87%AA%E7%BC%96%E7%A0%81%E7%AE ...

  8. Centos之压缩和解压缩命令

    常用压缩格式:.zip .gz .bz2 常用压缩格式:.tar.gz  .tar.bz2 zip格式压缩 zip压缩文件名 源文件 压缩文件 zip -r 压缩文件名 源目录 压缩目录 [root@ ...

  9. oracle创建job和删除job

    https://blog.csdn.net/u010001043/article/details/56479774

  10. Mysql安装(绿色版安装)

    一:下载 1.官网 https://dev.mysql.com/ 2.下载 3.下载 二:安装 1.将官网上下载的包进行解压 2.以管理员的身份运行DOS安装 进入mysql的bin目录 运行mysq ...