题目连接

  • 题意:

    给n*m的0/1矩阵,q次操作,每次有两种:1)将x,y位置值翻转 2)计算以(x,y)为边界的矩形的面积最大值

    (1 ≤ n, m, q ≤ 1000)
  • 分析:

    考虑以(x,y)为下边界的情况,h=(x,y)上边最多的连续1的个数。那么递减的枚举,对于当前hx,仅仅须要看两側能到达的最远距离,使得h(x,ty)不大于h就可以。之后的枚举得到的两側距离大于等于之前的,所以继续之前的两側距离继续枚举就可以。
const int maxn = 1100;

int n, m, q;
int ipt[maxn][maxn];
int up[maxn][maxn], dwn[maxn][maxn], lft[maxn][maxn], rht[maxn][maxn];
int len[maxn];
void updaterow(int r)
{
FE(j, 1, m)
lft[r][j] = (ipt[r][j] == 1 ? lft[r][j - 1] + 1 : 0);
FED(j, m, 1)
rht[r][j] = (ipt[r][j] == 1 ? rht[r][j + 1] + 1 : 0);
}
void updatecol(int c)
{
FE(i, 1, n)
up[i][c] = (ipt[i][c] == 1 ? up[i - 1][c] + 1 : 0);
FED(i, n, 1)
dwn[i][c] = (ipt[i][c] == 1 ? dwn[i + 1][c] + 1 : 0);
}
int maxarea(int s, int len[], int thes)
{
int l = s, r = s, ret = 0;
FED(i, len[s], 1)
{
while (l >= 1 && len[l] >= i)
l--;
while (r <= thes && len[r] >= i)
r++;
ret = max(ret, i * (r - l - 1));
}
return ret;
} int main()
{
while (~RIII(n, m, q))
{
FE(i, 1, n) FE(j, 1, m)
RI(ipt[i][j]);
FE(i, 1, n)
updaterow(i);
FE(j, 1, m)
updatecol(j);
REP(kase, q)
{
int op, x, y;
RIII(op, x, y);
if (op == 1)
{
ipt[x][y] ^= 1;
updatecol(y);
updaterow(x);
}
else
{
int ans = max(maxarea(y, up[x], m), maxarea(y, dwn[x], m));
FE(i, 1, n)
len[i] = lft[i][y];
ans = max(ans, maxarea(x, len, n));
FE(i, 1, n)
len[i] = rht[i][y];
ans = max(ans, maxarea(x, len, n));
WI(ans);
}
}
}
return 0;
}

Codeforces Round #248 (Div. 1)——Nanami&#39;s Digital Board的更多相关文章

  1. Codeforces Round #248 (Div. 1)——Ryouko&#39;s Memory Note

    题目连接 题意: 给n和m,一行m个1<=x<=n的数.记c=.如今仅仅能选择一个数x变成y,序列中全部等于x的值都变成y,求最小的c 分析: 对于一个数x,把与他相邻的所有的非x的数所有 ...

  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. 1) B. Nanami's Digital Board 暴力 前缀和

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

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

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

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

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

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

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

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

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

  9. Codeforces Round #313 (Div. 1) Gerald&#39;s Hexagon

    http://codeforces.com/contest/559/problem/A 题目大意:按顺序给出一个各内角均为120°的六边形的六条边长,求该六边形能分解成多少个边长为1的单位三角形. 解 ...

随机推荐

  1. 《c陷阱与缺陷》笔记--注意边界值

    如果要自己实现一个获取绝对值的函数,应该都没有问题,我这边也自己写了一个: void myabs(int i){ if(i>=0){ printf("%d\n",i); }e ...

  2. VS2013中安装配置和使用Boost库

    源地址:http://www.itnose.net/detail/6077953.html 时间:2014.07.24 地点:基地 ---------------------------------- ...

  3. tar.gz文件命名和压缩解压方法

    tar.gz文件命名 tar这是文件打成一个包,无压缩; gz同gzip标记的包.tar文件压缩; 所以它成为一个.tar.gz档 压缩 # tar cvfz backup.tar.gz /xxx/ ...

  4. OpenRisc-50-or1200的freeze模块分析

    引言 之前,我们分析or1200的控制通路中的sprs模块和except模块,本小节,我们就分析一下or1200控制通路的最后一个模块,就是freeze模块. 1,整体分析 freeze模块,顾名思义 ...

  5. Cocos2dx 3.x创建Layer的步骤

    创建 1.新建类文件.注意文件夹为Classes下.否则文件不能正常找到. 2.改动预编译头.如用VS,默觉得#pragma once,为了兼容,改为#ifndef | #define | #endi ...

  6. cocos2d-x CCNode类

    文章引用自http://blog.csdn.net/qiurisuixiang/article/details/8763260 1 CCNode是cocos2d-x中一个非常重要的类.CCNode是场 ...

  7. XmlDocument.Load()加载xml文件时,提示分析 EntityName 时出错的问题。

    今天一个接口突然报错,错误是: 分析 EntityName 时出错. 行 35,位置 90. xmlDoc.Load(System.Web.HttpContext.Current.Server.Map ...

  8. ZOJ 1584:Sunny Cup 2003 - Preliminary Round(最小生成树&amp;&amp;prim)

    Sunny Cup 2003 - Preliminary Round April 20th, 12:00 - 17:00 Problem E: QS Network In the planet w-5 ...

  9. Android 自己定义View (二) 进阶

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24300125 继续自己定义View之旅.前面已经介绍过一个自己定义View的基础 ...

  10. codeforces#256DIV2 D题Multiplication Table

    题目地址:http://codeforces.com/contest/448/problem/D 当时是依照找规律做的,规律倒是找出来了,可是非常麻烦非常麻烦. . 看到前几名的红名爷们3分钟就过了, ...