Problem Statement

There is an $N \times M$ grid, where the square at the $i$-th row from the top and $j$-th column from the left has a non-negative integer $A_{i,j}$ written on it.

Let us choose a rectangular region $R$.

Formally, the region is chosen as follows.

  • Choose integers $l_x, r_x, l_y, r_y$ such that $1 \le l_x \le r_x \le N, 1 \le l_y \le r_y \le M$.
  • Then, square $(i,j)$ is in $R$ if and only if $l_x \le i \le r_x$ and $l_y \le j \le r_y$.

Find the maximum possible value of $f(R) = $ (the sum of integers written on the squares in $R$) $\times$ (the smallest integer written on a square in $R$).

Constraints

  • All input values are integers.
  • $1 \le N,M \le 300$
  • $1 \le A_{i,j} \le 300$

这题有一万种做法。

枚举最小值 \(x\),现在要求一个权值和最大的矩阵,满足所有数的最小值不小于 \(x\)。

设 \(s_{i,j}\) 为 \((i,j)\) 往上最多有多少个数是不小于 \(x\) 的,然后对于某一行的某个区间,他往上能有多高取决于这个区间中所有数的最小值。

区间的最小值? 考虑单调栈求出这一行下一个和上一个比 \(v_{i,j}\) 小的区间,然后在这段区间之间的高度就取决于 \(v_{i,j}\) 的高度,二位前缀和统计即可。

#include<bits/stdc++.h>
using namespace std;
const int N=305;
typedef long long LL;
int n,m,st[N],s[N][N],ls[N],nx[N],tp,a[N][N],v[N][N];
LL p[N][N],ans;
LL ask(int ax,int ay,int bx,int by)
{
return p[bx][by]+p[ax-1][ay-1]-p[ax-1][by]-p[bx][ay-1];
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",a[i]+j),p[i][j]=p[i][j-1]+a[i][j];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
p[i][j]+=p[i-1][j];
for(int i=1;i<=300;i++)
{
for(int j=1;j<=n;j++)
{
for(int k=1;k<=m;k++)
{
if(a[j][k]>=i)
v[j][k]=v[j-1][k]+1;
else
v[j][k]=0;
}
}
for(int j=1;j<=n;j++)
{
for(int k=1;k<=m;k++)
ls[k]=0,nx[k]=m+1;
for(int k=1;k<=m;k++)
{
while(tp&&v[j][st[tp]]>v[j][k])
nx[st[tp--]]=k;
st[++tp]=k;
}
tp=0;
for(int k=m;k;k--)
{
while(tp&&v[j][st[tp]]>v[j][k])
ls[st[tp--]]=k;
st[++tp]=k;
}
for(int k=1;k<=m;k++)
ans=max(ans,1LL*i*ask(j-v[j][k]+1,ls[k]+1,j,nx[k]-1)); }
}
printf("%lld",ans);
}

[ABC311G] One More Grid Task的更多相关文章

  1. Libsvm:脚本(subset.py、grid.py、checkdata.py) | MATLAB/OCTAVE interface | Python interface

    1.脚本 This directory includes some useful codes: 1. subset selection tools. (子集抽取工具) subset.py 2. par ...

  2. SZU-A22

    Problem(A22):Party Judge InfoMemory Limit: 32768KBCase Time Limit: 10000MSTime Limit: 10000MSJudger: ...

  3. SVM应用

    我在项目中应用的SVM库是国立台湾大学林智仁教授开发的一套开源软件,主要有LIBSVM与LIBLINEAR两个,LIBSVM是对非线性数据进行分类,大家也比较熟悉,LIBLINEAR是对线性数据进行分 ...

  4. PatentTips – GPU Saving and Restoring Thread Group Operating State

    BACKGROUND OF THE INVENTION The present invention relates generally to single-instruction, multiple- ...

  5. 多线程之异步编程: 经典和最新的异步编程模型, IAsyncInfo 与 Task 相互转换

    经典的异步编程模型(IAsyncResult) 最新的异步编程模型(async 和 await) 将 IAsyncInfo 转换成 Task 将 Task 转换成 IAsyncInfo 示例1.使用经 ...

  6. 多线程之任务: Task 基础, 多任务并行执行, 并行运算(Parallel)

    Task - 基于线程池的任务(在 System.Threading.Tasks 命名空间下) 多 Task 的并行执行 Parallel - 并行计算(在 System.Threading.Task ...

  7. 重新想象 Windows 8 Store Apps (43) - 多线程之任务: Task 基础, 多任务并行执行, 并行运算(Parallel)

    [源码下载] 重新想象 Windows 8 Store Apps (43) - 多线程之任务: Task 基础, 多任务并行执行, 并行运算(Parallel) 作者:webabcd 介绍重新想象 W ...

  8. 重新想象 Windows 8 Store Apps (44) - 多线程之异步编程: 经典和最新的异步编程模型, IAsyncInfo 与 Task 相互转换

    [源码下载] 重新想象 Windows 8 Store Apps (44) - 多线程之异步编程: 经典和最新的异步编程模型, IAsyncInfo 与 Task 相互转换 作者:webabcd 介绍 ...

  9. hdu 1885 Key Task

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1885 Key Task Description The Czech Technical Univers ...

  10. Codeforces Round #249 (Div. 2) D. Special Grid 枚举

    题目链接: http://codeforces.com/contest/435/problem/D D. Special Grid time limit per test:4 secondsmemor ...

随机推荐

  1. 《SQL与数据库基础》19. 日志

    目录 日志 错误日志 二进制日志 日志格式 日志查看 日志删除 查询日志 慢查询日志 本文以 MySQL 为例 日志 错误日志 错误日志是 MySQL 中最重要的日志之一,它记录了当 mysql 启动 ...

  2. LeetCode297:hard级别中最简单的存在,java版,用时击败98%,内存击败百分之九十九

    本篇概览 因为欣宸个人水平有限,在刷题时一直不敢面对hard级别的题目,生怕出现一杯茶一包烟,一道hard做一天的窘境 这种恐惧心理一直在,直到遇见了它:LeetCode297,建议不敢做hard题的 ...

  3. redis基本数据类型 SortedSet

    SortedSet命令练习 将班级的下列学生得分存入Redis的SortedSet中:Jack 85, Lucy 89, Rose 82, Tom 95,Jerry 78, Amy 92, Miles ...

  4. Python 列表操作指南3

    示例,将新列表中的所有值设置为 'hello': newlist = ['hello' for x in fruits] 表达式还可以包含条件,不像筛选器那样,而是作为操纵结果的一种方式: 示例,返回 ...

  5. 前端三件套系例之BootStrap——BootStrap基础、 BootStrap布局

    文章目录 1 BootStrap基础 1 什么是BootStrap 2 BootStrap的版本 3 BootStrap 下载 4 CDN服务 5 目录结构 6 基本模板 7 浏览器支持 8 浏览器兼 ...

  6. Go语言精进之路目录

    目录 一.介绍 01.Go 语言的前生今世 二.开发环境搭建 01.Go 语言开发环境搭建 三.初识GO语言 01.Go 多版本管理工具 02.第一个 Go 程序"hello,world&q ...

  7. ChatGPT API Transition Guide

    ChatGPT API Transition Guide How to get started Written by Joshua J.. Updated over a week ago Prompt ...

  8. 小白CNN入门指导

    小白CNN入门指导 这几天一直在小白入门学习卷积层以准备组会,以下是我自学理解内容,若有错误的地方请各位评论指出 数学部分 一 卷积层 \[输入 32*32*3 (input neurons) \] ...

  9. WPF绘图(一):几何(Geometry)与形状(Shape)

    1. Geometry 在数学中,我们可以用一个方程描述圆:x2+y2=25.这个方程描述的是,一个半径为5,中心点在(0,0)的圆.这种纯数学的描述就是Geometry(几何). 但此时,这个&qu ...

  10. tunm, 一种对标JSON的二进制数据协议

    Tunm simple binary proto 一种对标JSON的二进制数据协议 支持的数据类型 基本支持的类型 "u8", "i8", "u16& ...