题目链接:

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 nm 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 opx, 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.

 
Examples
 
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
output
0
2
6
input
3 3 4
1 1 1
1 1 1
1 1 1
2 2 2
1 2 2
2 1 1
2 2 1
output
6
3
3
 题意: 给一个n*m网格,每次要么变换其中一个位置,0变1或者1变0,询问的是(x,y)为一个矩形边上一点,这个矩形全部为1,最多有多少个1;

思路:

还记得以前有一个题目是矩形宽都为1,把矩形放在一起形成的区域求其中的最大矩形的面积,当时是用的单调栈,这个只是要求4次罢了;

4次分别是这个点在矩形的上下边和左右边;

然后求一个最大面积,当然这个点一定在矩形边上,那么这个点(x,y)的高度一定是最高的,两边都是依次递减的到0,我们可以把这些高排序,然后再取最大的面积就好了;

具体的看代码吧;

AC代码:

#include <bits/stdc++.h>
/*#include <vector>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>
*/
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
F && (num=-num);
}
int stk[], tp;
template<class T> inline void print(T p) {
if(!p) { puts(""); return; }
while(p) stk[++ tp] = p%, p/=;
while(tp) putchar(stk[tp--] + '');
putchar('\n');
} const LL mod=1e9+;
const double PI=acos(-1.0);
const LL inf=1e14;
const int N=1e5+; int n,m,q;
int a[][],h[][][],le[][][],temp[];
void Init()
{
for(int j=;j<=m;j++)
{
for(int i=;i<=n;i++)
{
if(a[i][j])h[][i][j]=h[][i-][j]+;
else h[][i][j]=;
}
for(int i=n;i>;i--)
{
if(a[i][j])h[][i][j]=h[][i+][j]+;
else h[][i][j]=;
}
}
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(a[i][j])le[][i][j]=le[][i][j-]+;
else le[][i][j]=;
}
for(int j=m;j>;j--)
{
if(a[i][j])le[][i][j]=le[][i][j+]+;
else le[][i][j]=;
}
}
}
void change (int x,int y)
{
a[x][y]^=;
for(int i=x;i<=n;i++)if(a[i][y])h[][i][y]=h[][i-][y]+;else h[][i][y]=;
for(int i=x;i>;i--)if(a[i][y])h[][i][y]=h[][i+][y]+;else h[][i][y]=;
for(int i=y;i<=m;i++)if(a[x][i])le[][x][i]=le[][x][i-]+;else le[][x][i]=;
for(int i=y;i>;i--)if(a[x][i])le[][x][i]=le[][x][i+]+;else le[][x][i]=;
}
int cmp(int x,int y)
{
return x>y;
}
void solve(int x,int y)
{
int ans=,l,r;
for(int i=;i<=;i++)
{
temp[y]=h[i][x][y];
for(r=y+;r<=m&&h[i][x][r];r++)if(h[i][x][r]>temp[r-])temp[r]=temp[r-];else temp[r]=h[i][x][r];
for(l=y-;l>&&h[i][x][l];l--)if(h[i][x][l]>temp[l+])temp[l]=temp[l+];else temp[l]=h[i][x][l];
r--;l++;
sort(temp+l,temp+r+,cmp);
for(int j=l;j<=r;j++)
ans=max(ans,temp[j]*(j-l+)); temp[x]=le[i][x][y];
for(r=x+;r<=n&&le[i][r][y];r++)if(le[i][r][y]>temp[r-])temp[r]=temp[r-];else temp[r]=le[i][r][y];
for(l=x-;l>&&le[i][l][y];l--)if(le[i][l][y]>temp[l+])temp[l]=temp[l+];else temp[l]=le[i][l][y];
r--;l++;
sort(temp+l,temp+r+,cmp);
for(int j=l;j<=r;j++)
ans=max(ans,temp[j]*(j-l+));
}
print(ans);
} int main()
{
read(n);read(m);read(q);
Riep(n)Rjep(m)read(a[i][j]);
int flag,x,y;
Init();
while(q--)
{
read(flag);read(x);read(y);
if(flag==)change(x,y);
else solve(x,y);
}
return ;
}

codeforces 434B B. Nanami's Digital Board(分治)的更多相关文章

  1. Codeforces Round #248 (Div. 1) B. Nanami's Digital Board 暴力 前缀和

    B. Nanami's Digital Board 题目连接: http://www.codeforces.com/contest/434/problem/B Description Nanami i ...

  2. Nanami's Digital Board CodeForces - 434B (棋盘dp)

    大意: 给定01矩阵, m个操作, 操作1翻转一个点, 操作2求边界包含给定点的最大全1子矩阵 暴力枚举矩形高度, 双指针统计答案 #include <iostream> #include ...

  3. Nanami's Digital Board

    题意: 给出点(x1,y1),求以x=x1为上边界,或下边界:以y=y1为左边界,或右边界矩形的最大值(矩形内所有的点均为1) 定义四个数组lft[][],rht[][],up[][],down[][ ...

  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. codeforces248(div1) B Nanami&#39;s Digital Board

    q次询问,每次询问能够对矩阵某一个值改变(0变1.1变0) 或者是查询子矩阵的最大面积,要求这个这个点在所求子矩阵的边界上,且子矩阵各店中全为1 用up[i][j]表示(i,j)这个点向上能走到的最长 ...

  6. codeforces 161D Distance in Tree 树上点分治

    链接:https://codeforces.com/contest/161/problem/D 题意:给一个树,求距离恰好为$k$的点对是多少 题解:对于一个树,距离为$k$的点对要么经过根节点,要么 ...

  7. Codeforces 437D The Child and Zoo - 树分治 - 贪心 - 并查集 - 最大生成树

    Of course our child likes walking in a zoo. The zoo has n areas, that are numbered from 1 to n. The ...

  8. Codeforces Beta Round #10 C. Digital Root 数学

    C. Digital Root 题目连接: http://www.codeforces.com/contest/10/problem/C Description Not long ago Billy ...

  9. Educational Codeforces Round 41 967 E. Tufurama (CDQ分治 求 二维点数)

    Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama (CDQ分治 求 二维点数) time limit per test 2 ...

随机推荐

  1. 深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换 [转]

    本篇文章是对c++中的char*与wchar_t*与string以及wstring之间的相互转换进行了详细的分析介绍,需要的朋友参考下. #ifndef USE_H_ #define USE_H_ # ...

  2. 跟SAP系统集成的Android应用

    首先吐槽一点,这是我的第一个Android应用,很糙. 这个应用适合于上了SAP系统的企业内部使用,并且限于制造型MTO模式,需要针对生产订单报工操作的场景,因为此应用主要的一个目的,就是用来方便报工 ...

  3. ......那么Win8.1怎么去掉文件夹?

    (从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期2014-05-11) 细心的朋友会发现,在Win8.1这台电脑(计算机)中,除了我们最熟悉的磁盘外,还新增了视频.图片.文档.下载.音 ...

  4. jsp中使用动态数据进行mySQL数据库的两种操作方法

    使用动态数据进行数据库内容的增删改查操作有两种方法: 在此定义数据库连接为conn 假设有表单进行数据输入并提交到处理页面一种是使用预编译格式: 其格式如下: String name = reques ...

  5. state与status的区别

    status 指人时暗指相对的地位,指物时相当于 situation.situation 较狭义地指由环境综合决定的特定时间上的状态或情形. state 人或物存在或所处的状态,和 condition ...

  6. jQuery性能优化的28个建议

    我一直在寻找有关jQuery性能优化方面的小窍门,能让我那臃肿的动态网页应用变得轻便些.找了很多文章后,我决定将最好最常用的一些优化性能的建议列出来.我也做了一个jQuery性能优化的简明样式表,你可 ...

  7. Windows API 磁盘

    这里的磁盘就是你的C,D,E,F,G盘啦 那么来看看吧windows Api来获取信息的呢 (1)DWORD GetLogicalDrives(void) 返回值是一个32位整形 32位每一位表示一个 ...

  8. VK Cup 2012 Qualification Round 2 C. String Manipulation 1.0 字符串模拟

    C. String Manipulation 1.0 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/pr ...

  9. Codeforces Round #308 (Div. 2)B. Vanya and Books 数学

    B. Vanya and Books Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/pr ...

  10. UESTC 890 Card Trick(DP 纸牌魔术)

    题意  给你一些牌  所有正面朝下放桌子上   你选一个起点    翻开那张牌   牌上的数字是几就向前走几步   J,Q,K 都是向前走10步  A向前走11步   知道向前走相应的步数后超过了终点 ...