q次询问,每次询问能够对矩阵某一个值改变(0变1。1变0) 或者是查询子矩阵的最大面积,要求这个这个点在所求子矩阵的边界上,且子矩阵各店中全为1

用up[i][j]表示(i,j)这个点向上能走到的最长高度  若(i,j)为0 则up[i][j]值为0

同理。维护down,left, right数组

则每次查询时。从up[i][j]枚举至1作为子矩阵的高度,然后途中分别向左右扩展。若up[i][j - 1] >= up[i][j],则可向左扩展一个单位,答案为(r - l - 1) * 高度

同理,四个方向分别枚举

//#pragma comment(linker, "/STACK:102400000,102400000")
//HEAD
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm> #include <queue>
#include <string>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <cstdlib> using namespace std;
//LOOP
#define FE(i, a, b) for(int i = (a); i <= (b); ++i)
#define FED(i, b, a) for(int i = (b); i>= (a); --i)
#define REP(i, N) for(int i = 0; i < (N); ++i)
#define CLR(A,value) memset(A,value,sizeof(A))
//STL
#define PB push_back
//INPUT
#define RI(n) scanf("%d", &n)
#define RII(n, m) scanf("%d%d", &n, &m)
#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define RS(s) scanf("%s", s)
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int MAXN = 1010; #define FF(i, a, b) for(int i = (a); i < (b); ++i)
#define FD(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define CPY(a, b) memcpy(a, b, sizeof(a))
#define FC(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define EQ(a, b) (fabs((a) - (b)) <= 1e-10)
#define ALL(c) (c).begin(), (c).end()
#define SZ(V) (int)V.size()
#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)
#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)
#define WI(n) printf("%d\n", n)
#define WS(s) printf("%s\n", s)
typedef vector <int> VI;
typedef unsigned long long ULL;
const double eps = 1e-10;
const LL MOD = 1e9 + 7;
const int maxn = 1010; int ipt[maxn][maxn];
int up[maxn][maxn], dwn[maxn][maxn], rht[maxn][maxn], lft[maxn][maxn];
int len[maxn], n, m; void update_col(int y)
{
FE(i, 1, n)
if (ipt[i][y])
up[i][y] = up[i - 1][y] + 1;
else up[i][y] = 0;
FED(i, n, 1)
if (ipt[i][y])
dwn[i][y] = dwn[i + 1][y] + 1;
else
dwn[i][y] = 0;
} void update_row(int x)
{
FE(j, 1, m)
if (ipt[x][j])
lft[x][j] = lft[x][j - 1] + 1;
else lft[x][j] = 0;
FED(j, m, 1)
if (ipt[x][j])
rht[x][j] = rht[x][j + 1] + 1;
else rht[x][j] = 0;
} int solve(int sta, int hei, int con)
{
int lm = sta, rm = sta;
int ans = 0;
for (int h = hei; h >= 1; h--)
{
while (lm >= 1 && len[lm] >= h)
lm--;
while (rm <= con && len[rm] >= h)
rm++;
ans = max(ans, h * (rm - lm - 1));
}
return ans;
} int main()
{
//freopen("0.txt", "r", stdin);
int q, x, y, op;
cin >> n >> m >> q;
FE(i, 1, n)
FE(j, 1, m)
RI(ipt[i][j]);
FE(i, 1, n)
update_row(i);
FE(j, 1, m)
update_col(j);
while (q--)
{
RIII(op, x, y);
if (op == 1)
{
ipt[x][y] ^= 1;
update_row(x);
update_col(y);
// cout << "UP " << endl;
// FE(i, 1, n) {
// FE(j, 1, m)
// cout << up[i][j] << ' ';
// cout <<endl;
// }
// cout << "----" << endl;
// cout << "right " << endl;
// FE(i, 1, n) {
// FE(j, 1, m)
// cout << rht[i][j] << ' ';
// cout <<endl;
// }
// cout << "----" << endl;
}
else
{
int ans = 0;
FE(j, 1, m) len[j] = up[x][j];
ans = max(ans, solve(y, len[y], m));
FE(j, 1, m) len[j] = dwn[x][j];
ans = max(ans, solve(y, len[y], m));
FE(i, 1, n) len[i] = lft[i][y];
ans = max(ans, solve(x, len[x], n));
FE(i, 1, n) len[i] = rht[i][y];
ans = max(ans, solve(x, len[x], n));
WI(ans);
}
}
return 0;
}

codeforces248(div1) B Nanami&#39;s Digital Board的更多相关文章

  1. 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)为 ...

  2. codeforces 434B B. Nanami's Digital Board(分治)

    题目链接: B. Nanami's Digital Board time limit per test 1 second memory limit per test 256 megabytes inp ...

  3. 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 ...

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

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

  5. Nanami's Digital Board

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

  6. HDU1163 Eddy&#39;s digital Roots【九剩余定理】

    Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  7. Eddy&#39;s digital Roots

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission ...

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

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

  9. FBOSS: Building Switch Software at Scale

    BOSS: 大规模环境下交换机软件构建 本文为SIGCOMM 2018 论文,由Facebook提供. 本文翻译了论文的关键内容. 摘要: 在网络设备(例如交换机和路由器)上运行的传统软件,通常是由供 ...

随机推荐

  1. java数组简单逻辑代码

    package cuteSnow; public class HelloWorld { // 遍历数组里面的每个数字 public static void print(int[] array){ St ...

  2. linux 上安装 redis

    一.安装gcc Redis是c语言开发的. 安装 redis 需要 c 语言的编译环境.如果没有 gcc 需要在线安装. yum install gcc-c++ 二.下载 redis 链接:https ...

  3. mysql-5.7.10-winx64 安装

    安装ZIP中的EXE文件后,找到安装目录中的my-default.ini加入代码 1 2 3 4 5 6 #新设置的 [mysql] default-character-set=utf8 #新设置的 ...

  4. POJ——T2352 Stars

    http://poj.org/problem?id=2352 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 46592   ...

  5. ACM这一路

    出自自己内心的声音.         大学已经读了一年,自己也老了一岁. 从開始的什么都不懂,到如今的懂了也不想多说什么,说多了也是累.在大学其中唯一还在执着的是ACM.这个也是我唯一能执着的东西,由 ...

  6. Collection 和 Collections 的差别?

    Collection 是 java.util 下的接口,它是各种集合的父接口,继承于它的 接口主要有 Set 和 List:Collections 是个 java.util 下的类.是针对集合的 帮助 ...

  7. OS - 线程和进程的差别

    进程是资源分配的基本单位,又是调度执行的基本单位.比如.用户执行自己的程序,系统就创建一个进程.并为它分配资源,包含各种表.内存空间.磁盘空间.I/O设备等. 然后.把该进程放入进程的就绪队列.进程调 ...

  8. Wing IDE 怎样设置 python版本号

    机器上同一时候装了Python3和Python2,使用Wing IDE, 由于Python2和3是有非常大的差别的,所以时不时的须要更改IDE使用的Python版本号.以下介绍方法: 1.打开Edit ...

  9. error[No partition metadata for topic test-1 due to kafka.common.LeaderNotAvailableException]

    http://stackoverflow.com/questions/23228222/running-into-leadernotavailableexception-when-using-kafk ...

  10. Android学习之——自己搭建Http框架(2)——框架扩展

    · 本文主要解说的是Json指定转化成对象返回.下载进度更新,随时取消Request请求 一.Json指定转化成对象返回 上篇文章主要讲基础的框架搭建起来了,这次须要做一些些的扩展,这里Json转化用 ...