一、题目

  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. Python 相关

    循环使用迭代器 Python中使用for循环时,内置容器的默认循环都是有迭代器的.使用迭代器每次只会读出一小部分到内存,不断往后next. 通常建议在没有必要的情况下不使用for key,value ...

  2. sqlmap在https情况下的一个错误

    对于https网站,使用sqlmap可能会出现如下错误.使用–force-ssl无效. https证书有问题 方法 本地建立proxy.php,内容为 <?php $url = "ht ...

  3. Inkscape svg彩色图转灰度图

    操作: Ctrl+A 全选所有对象, 然后使用滤镜渲染成灰度图, 至于这个RGB比值, 看个人需求, 标准情况下rgb2gray是0.299 * R + 0.587 * G + 0.114 * B 原 ...

  4. Flutter Widgets

    Flutter Widgets Flutter 组件 Syncfusion Flutter Widgets 所有组件均支持即装即用的 Android,iOS和 Web not free https:/ ...

  5. GitHub SSH key

    GitHub SSH key https://help.github.com/en/github/authenticating-to-github steps HTTPS clone !== SSH ...

  6. node --experimental-modules & node.js ES Modules

    node --experimental-modules & node.js ES Modules how to run esm modules in node.js cli $ node -v ...

  7. OSS & Object Storage Service

    OSS & Object Storage Service Object Storage Service https://en.wikipedia.org/wiki/Object_storage ...

  8. taro demos & taro 组件库

    taro demos & taro 组件库 ui demo https://github.com/qit-team/taro-yanxuan https://github.com/fengch ...

  9. Flutter: provider 使用小部件的小部件构建的依赖注入系统

    文档 dependencies: provider: import 'package:dart_printf/dart_printf.dart'; import 'package:flutter/ma ...

  10. NGK算力生态建设者狂欢!SPC之后又有VAST!

    想致富,先挖矿.这句话已经成为了币圈的一句名言.挖矿一词始终贯穿着区块链以及数字加密领域. 据小道消息透露,NGK官最近将会推出两款挖矿产品---SPC星空币以及其子币VAST维萨币. 下面笔者就来一 ...