当前位置:网站首页>E. OpenStreetMap (2D monotone queue)
E. OpenStreetMap (2D monotone queue)
2022-07-26 01:47:00 【to cling】
Codeforces Round #574 (Div. 2)
Problem
Given a size of n × m n \times m n×m Matrix h, Find all sizes as a × b a \times b a×b In the submatrix of Sum of minimum values .
Solution
Answer key
Find out h in , The length in all rows is b The minimum value in the sliding window of , Store its results in f Array
Find out f in , The length in all columns is a The minimum value in the sliding window of , The result is that all sizes are a × b a \times b a×b The minimum value in the submatrix of
Time complexity O ( n m ) O(nm) O(nm)
Code
int h[3003][3003], g[3003 * 3003];
int f[3003][3003];
int main()
{
IOS;
int n, m, a, b; cin >> n >> m >> a >> b;
int x, y, z; cin >> g[0] >> x >> y >> z;
for (int i = 1; i <= n * m; i++)
g[i] = ((ll)g[i - 1] * x + y) % z;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
h[i][j] = g[(i - 1) * m + j - 1];
// Find the length of all lines is b The minimum value in the window of
for (int i = 1; i <= n; i++)
{
// The operation array is h
deque <int> q;
for (int j = 1; j <= m; j++)
{
if (!q.empty() && q.back() - q.front() + 1 >= b) q.pop_front();
while (!q.empty() && h[i][q.back()] >= h[i][j]) q.pop_back();
q.push_back(j);
f[i][j] = h[i][q.front()];
}
}
// Find the length of all columns is a The minimum value in the window of ( In essence a * b The minimum value of the matrix )
for (int j = 1; j <= m; j++)
{
// The operation array is f
deque<int> q;
for (int i = 1; i <= n; i++)
{
if (!q.empty() && q.back() - q.front() + 1 >= a) q.pop_front();
while (!q.empty() && f[q.back()][j] >= f[i][j]) q.pop_back();//
q.push_back(i);
h[i][j] = f[q.front()][j];// Here is the optimization space , So just use h Come and save
}
}
ll ans = 0;
for (int i = a; i <= n; i++)
for (int j = b; j <= m; j++)
ans += h[i][j];
cout << ans << endl;
return 0;
}
边栏推荐
- Is it safe to buy funds in stock accounts? Professional answers
- flutter 下 grpc list没有Setter 方法 ,如何使用相关属性
- 3、 Pinda general permission system__ pd-tools-swagger2
- 销量连连夺冠,五菱的成功秘诀只有低价吗?
- y77.第四章 Prometheus大厂监控体系及实战 -- prometheus的服务发现机制(八)
- SOC first project hello_ world
- pt-onnx-ncnn转换的问题记录(接yolov5训练)
- How to use the pagoda panel to deploy the full stack project of node to the server
- Ideal Path(UVA - 1599)
- AUTOCAD——计算面积的方法
猜你喜欢

图像批处理高斯滤波降噪+峰值信噪比计算

Pt onnx ncnn conversion problem record (followed by yolov5 training)

Implementation of recommendation system collaborative filtering in spark

推荐系统-协同过滤在Spark中的实现

excel中怎么显示数字/英文时间

The best way to practice Animation: cover transition
![[untitled]](/img/bf/7c4be5b442d12b2b1896f197be30fa.png)
[untitled]

Leetcode537. Complex multiplication (yes, solved)

C language enumeration types and unions

餐饮连锁门店重塑增长背后的数字化转型
随机推荐
8. Learn Mysql to create data tables
Leetcode 537. complex multiplication (netizens' thoughts, ashamed)
Is it safe to buy funds on e fund? Professional answers
Speech comprehension center comprehension summary
【深入浅出玩转FPGA学习11----Testbench书写技巧2】
Three modes of CPU
Oracle is nested at multiple levels, and the alias problem of the table cannot be found
My Mysql to MySQL data table synchronization, only the code written in the first order will take effect, and the rest will not take effect. This may be
6 + 1 skills of Software Test Engineer
C语言中的整型数据类型(你真的了解吗)
Is it safe to open an account for stock speculation through the online account manager?
3059. Sculpture (jzoj)
Niuke - bm39 serialized binary tree [hard]
CPU的三种模式
After reading this article, you should thoroughly understand how to do interface testing
flink sql 如何配置打印insert实参日志呢
Network layer 2 and layer 3 forwarding
言语理解中心理解总结
poj1521
Pt onnx ncnn conversion problem record (followed by yolov5 training)