当前位置: 首页 > news >正文

题目 3161: 蓝桥杯2023年第十四届省赛真题-子矩阵

 题目

 

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1010, mod = 998244353;
int g[N][N];
int rmin[N][N], rmax[N][N];
ll mmin[N][N], mmax[N][N];
int q[N * N];
int hh, tt;
int n, m, a, b;
int main()
{cin >> n >> m >> a >> b;for (int i = 1; i <= n; i++){for (int j = 1; j <= m; j++){cin >> g[i][j];}}for (int i = 1; i <= n; i++){hh = 0, tt = -1;for (int j = 1; j <= m; j++){if (hh <= tt && j - q[hh] + 1 > b)hh++;while (hh <= tt && g[i][q[tt]] >= g[i][j])tt--;q[++tt] = j;if (j >= b)rmin[i][j - b + 1] = g[i][q[hh]];}}for (int j = 1; j <= m; j++){hh = 0, tt = -1;for (int i = 1; i <= n; i++){if (hh <= tt && i - q[hh] + 1 > a)hh++;while (hh <= tt && rmin[q[tt]][j] >= rmin[i][j])tt--;q[++tt] = i;if (i >= a)mmin[i - a + 1][j] = rmin[q[hh]][j];}}for (int i = 1; i <= n; i++){hh = 0, tt = -1;for (int j = 1; j <= m; j++){if (hh <= tt && j - q[hh] + 1 > b)hh++;while (hh <= tt && g[i][q[tt]] <= g[i][j])tt--;q[++tt] = j;if (j >= b)rmax[i][j - b + 1] = g[i][q[hh]];}}for (int j = 1; j <= m; j++){hh = 0, tt = -1;for (int i = 1; i <= n; i++){if (hh <= tt && i - q[hh] + 1 > a)hh++;while (hh <= tt && rmax[q[tt]][j] <= rmax[i][j])tt--;q[++tt] = i;if (i >= a)mmax[i - a + 1][j] = rmax[q[hh]][j];}}ll ans = 0;for (int i = 1; i + a - 1 <= n; i++){for (int j = 1; j + b - 1 <= m; j++){ans = (ans + (mmin[i][j] * mmax[i][j]) % mod) % mod;}}cout << ans;
}


http://www.mrgr.cn/news/53619.html

相关文章:

  • Jmeter 实战 JDBC配置
  • 【linux故障处理】【Failed to restart nginx.service: Unit not found.】
  • 深度学习——循环神经网络RNN知识点小结(全)
  • JavaCV 图像灰度化处理
  • 来个Oracle一键检查
  • 签约!沃飞长空和民航二所签署战略合作协议
  • kubernetes(三)
  • 勤于奋身体倒下还是上来回答粉丝关于Adsense赚美金
  • 设计模式之设计模式分类
  • ESP32-IDF 通用定时器 GPTimer
  • LeetCode题练习与总结:拼接最大数--321
  • 小白学大模型 RAG:GraphRAG 概念、组成和流程,看完这一篇你就懂了!!
  • 出手!快手可灵开源版,AI视频生成整合包!
  • 84.【C语言】数据结构之顺序表的头部插入和删除
  • 医疗领域的RAG技术:如何通过知识图谱提升准确性
  • vb操作电子表格 文件夹内多表格 提取数据 在生成一个新表格
  • Leetcode—192. 统计词频【中等】(Shell)
  • 【树莓派】树莓派搭建个人服务器
  • Qt之QObject
  • Java并发编程深度解析:从基础到实战
  • Shades of Gray 算法
  • 问:MySQL数据库存储引擎及对应的锁有哪些?
  • ​AI Sketchnotes Generator——解锁创意表达的新方式
  • 83.【C语言】数据结构之顺序表的尾部插入和删除
  • C语言 | Leetcode C语言题解之第493题翻转对
  • [实时计算flink]DataStream连接器设置方法