一、题目

  OpenStreetMap

二、分析

  对于二维空间找区间最小值,那么一维的很多好用的都无法用了,这里可以用单调队列进行查找。

  先固定一个坐标,然后进行一维的单调队列操作,维护一个区间长度为$b$的最小值,可以确定一个数组$ans$。

  对于新数组,进行另一个维度的单调队列操作,找到$a*b$的最小值。(由于英语太差,读题目时理解成了是点在区间左上角的意思)

  写的时候一定注意第二次单调队列的对象数组是新数组。

三、AC代码

 1 #include <bits/stdc++.h>
2
3 using namespace std;
4 #define ll long long
5 #define Min(a,b) ((a)>(b)?(b):(a))
6 #define Max(a,b) ((a)>(b)?(a):(b))
7 const int maxn = 3e3 + 13;
8 ll h[maxn][maxn];
9 ll ans[maxn][maxn];
10
11 int que[maxn];
12 int ql, qr;
13
14 int main()
15 {
16 //freopen("input.txt", "r", stdin);
17 int n, m, a, b;
18 int x, y, z;
19 while(scanf("%d%d%d%d", &n, &m, &a, &b) != EOF)
20 {
21 int i, j;
22 ll g0;
23 scanf("%I64d%d%d%d", &g0, &x, &y, &z);
24 for(i = 1; i <= n; i++)
25 {
26 for(j = 1; j <= m; j++)
27 {
28 h[i][j] = g0;
29 g0 = (1ll*g0*x + y)%z;
30 }
31 }
32 for(i = 1; i <= n; i++)
33 {
34 ql = 0, qr = 0;
35 for(j = 1; j <= m; j++)
36 {
37 while(ql < qr && j - que[ql] >= b)
38 ql++;
39 while(ql < qr && h[i][j] <= h[i][que[qr-1]])
40 qr--;
41 que[qr++] = j;
42 ans[i][j] = h[i][que[ql]];
43 }
44 }
45 ll tmp = 0;
46 for(j = b; j <= m; j++)
47 {
48 ql = 0, qr = 0;
49 for(i = 1; i <= n; i++)
50 {
51 while(ql < qr && i - que[ql] >= a)
52 ql++;
53 while(ql < qr && ans[i][j] <= ans[que[qr-1]][j])
54 qr--;
55 que[qr++] = i;
56 if(i >= a)
57 tmp += ans[que[ql]][j];
58 }
59 }
60 printf("%I64d\n", tmp);
61 }
62 return 0;
63 }

Codeforces Round #574 (Div. 2) E. OpenStreetMap 【单调队列】的更多相关文章

  1. Codeforces Round #574 (Div. 2) E.OpenStreetMap

    题目链接 题目的意思就是给你一个矩阵你要求给定子矩阵的最小值的和 单调队列扫两边即可 #include <bits/stdc++.h> #define ll long long #defi ...

  2. Codeforces Round #574 (Div. 2)

    目录 Contest Info Solutions A. Drinks Choosing B. Sport Mafia C. Basketball Exercise D1. Submarine in ...

  3. Codeforces Round #574 (Div. 2) A~E Solution

    A. Drinks Choosing 有 $n$ 个人,每个人各有一种最喜欢的饮料,但是买饮料的时候只能同一种的两个两个买(两个一对) 学校只打算卖 $\left \lceil \frac{n}{2} ...

  4. Codeforces Round #574 (Div. 2)题解

    比赛链接 传送门 A题 题意 \(n\)个人每个人都有自己喜欢喝的\(vechorka\)口味,现在给你\(\lceil n/2\rceil\)箱\(vechorka\),每箱有两瓶,问最多能有多少个 ...

  5. Codeforces Round #622 (Div. 2)C(单调栈,DP)

    构造出的结果一定是一个单峰/\这种样子的 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ...

  6. Codeforces Round #305 (Div. 2) D 维护单调栈

    D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  7. Codeforces Round #574 (Div. 2)——C. Basketball Exercise(简单DP)

    题目传送门 题意: 输入n,给出两组均为 n个数字的数组a和b,轮流从a和b数组中取出一个数字,要求严格按照当前所选数字的数组下标比上一个所选数字的数组下标更大,计算能够取出的数字加起来的总和最大能为 ...

  8. Codeforces Round #574 (Div. 2)补题

    A. Drinks Choosing 统计每种酒有多少人偏爱他们. ki 为每种酒的偏爱人数. 输出ans = (n + 1)/2 >  Σki / 2 ? (n + 1)/2 - Σki / ...

  9. Codeforces Round #574 (Div. 2) D2. Submarine in the Rybinsk Sea (hard edition) 【计算贡献】

    一.题目 D2. Submarine in the Rybinsk Sea (hard edition) 二.分析 相比于简单版本,它的复杂地方在于对于不同长度,可能对每个点的贡献可能是有差异的. 但 ...

随机推荐

  1. Hexo准备---Node.js、Vue

    Hexo准备---Node.js.Vue 安装node.js 1.下载node 配置node.js环境官网下载,一直next就好,非常方便. 下载官网: http://nodejs.cn/downlo ...

  2. virtualBox 设置增强功能粘贴和拖放

    virtualBox 5.2.8 (在运行的虚拟里中) 设备 -> 安装增强功能 virtualBox 管理器中设置(要在虚拟机关机的情况下配置) 常规 -> 高级里设置双向粘贴和拖放

  3. 对于kmp求next数组的理解

    首先附上代码 1 void GetNext(char* p,int next[]) 2 { 3 int pLen = strlen(p); 4 next[0] = -1; 5 int k = -1; ...

  4. IIS6.0(CVE-2017-7269) 缓冲器溢出

    漏洞描述开启WebDAV服务对IIS 6.0存在缓冲区溢出漏洞都可以导致远程代码执行,所以对于目前的IIS 6.0用户而言,可用的变通方案就是关闭WebDAV服务. 漏洞编号CVE-2017-7269 ...

  5. React Hooks vs React Class vs React Function All In One

    React Hooks vs React Class vs React Function All In One React Component Types React Hooks Component ...

  6. algorithm & bitwise operation & the best leetcode solutions

    algorithm & bitwise operation & the best leetcode solutions leetcode 136 single-number the b ...

  7. bye MVA

    bye MVA https://mva.microsoft.com/

  8. Scalability & Scale-up & Scale-out

    Scalability & Scale-up & Scale-out 架构,弹性,伸缩性 Scalability 可扩展性 https://en.wikipedia.org/wiki/ ...

  9. Chrome & console.log & color & js

    Chrome & console.log & color & js console.log & color // OK log(`%cchat_list =\n%c${ ...

  10. xcode upgrade & git bug

    xcode upgrade & git bug ➜ op-static git checkout feature/select-seat-system Agreeing to the Xcod ...