子矩阵(十四届蓝桥杯python组A)

这题思路就是用两次单调队列。

下面是TIE的代码。9/10;用了priority_queue做单调队列,而不是手动写的。

(手写单调队列好麻烦~~~,脑子晕死,考试的时候过了9个点也ok,)

#include<iostream>
#include<queue>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<unordered_map>
#include<vector>
using namespace std;
const int N = 1E3+10;
const int mod = 998244353;
typedef long long ll;
typedef pair<int,int> pll;

priority_queue<pll> maxn[N];
priority_queue<pll,vector<pll>,greater<pll>> minn[N];
int maxnum[N][N];
int minnum[N][N];

priority_queue<pll> maxl[N];
priority_queue<pll,vector<pll>,greater<pll>> minl[N];


int main (){
	int n,m,a,b;cin>>n>>m>>a>>b;
	for(int i = 1;i<=n;++i){
		for(int j = 1;j<=m;++j){
			int a;cin>>a;
			maxn[i].push({a,j});
			minn[i].push({a,j});
			while(maxn[i].top().second<=j-b){
				maxn[i].pop();
			}
			while(minn[i].top().second<=j-b){
				minn[i].pop();
			}
			maxnum[i][j] = maxn[i].top().first;
			minnum[i][j] = minn[i].top().first;
		}

	}	
	ll hou = 0;
	ll ou = 0;
	for(int j = b;j<=m;++j){
		for(int i = 1;i<=n;++i){
			maxl[j].push({maxnum[i][j],i});
			minl[j].push({minnum[i][j],i});
			if(i>=a){
				while(maxl[j].top().second<=i-a){
					maxl[j].pop();
				}
				while(minl[j].top().second<=i-a){
					minl[j].pop();
				}
				hou = (ll)maxl[j].top().first*(ll)minl[j].top().first%mod;
				ou = (ou+hou)%mod;
				cout<<hou<<endl;
			}
		}
	}
	cout<<ou;
	return 0;
} 

单调队列

相关推荐

  1. 矩阵pythonA

    2024-03-22 16:14:01       19 阅读
  2. 省赛C++ A

    2024-03-22 16:14:01       16 阅读
  3. 2023第省赛C/C++大学A题解

    2024-03-22 16:14:01       17 阅读

最近更新

  1. adb 常用的命令总结

    2024-03-22 16:14:01       0 阅读
  2. gcc: options: -specs

    2024-03-22 16:14:01       0 阅读
  3. Python题解Leetcode Hot 100之栈和堆

    2024-03-22 16:14:01       0 阅读
  4. docker容器如何与本地配置文件关联

    2024-03-22 16:14:01       0 阅读
  5. SQL 字段类型-上

    2024-03-22 16:14:01       1 阅读
  6. C++ 入门04:数组与字符串

    2024-03-22 16:14:01       1 阅读
  7. 简谈设计模式之原型模式

    2024-03-22 16:14:01       1 阅读
  8. GPT带我学-设计模式-13策略模式

    2024-03-22 16:14:01       1 阅读
  9. 写一个字符设备的驱动步骤

    2024-03-22 16:14:01       1 阅读

热门阅读

  1. 【LeetCode-22.括号生成】

    2024-03-22 16:14:01       21 阅读
  2. L1-5 不变初心数分数 15

    2024-03-22 16:14:01       23 阅读
  3. 从政府工作报告探计算机行业发展

    2024-03-22 16:14:01       22 阅读
  4. 【leetcode热题】颠倒二进制位

    2024-03-22 16:14:01       23 阅读
  5. Unity构建详解(1)——SBP介绍

    2024-03-22 16:14:01       23 阅读
  6. unity自动引用生成

    2024-03-22 16:14:01       20 阅读
  7. ChatGPT:如何利用人工智能写出高质量论文

    2024-03-22 16:14:01       21 阅读
  8. LeetCode刷题——347. 前 K 个高频元素

    2024-03-22 16:14:01       24 阅读
  9. 下载NLP_gluedata数据集的脚本

    2024-03-22 16:14:01       20 阅读