一、题目

  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. 使用SignTool对软件安装包进行数字签名(二)--进行数字签名

    四.使用signcode.exe为安装程序.库或cab包签名 1.运行signcode.exe. 2.点击"下一步",选择需要签名的文件(安装程序.库或cab包). 3.点击&qu ...

  2. 杭电多校HDU 6586 String(预处理 + 贪心)题解

    题意: 给你一个串,现需要你给出一个子序列,满足26个约束条件,\(len(A_i) >= L_i\) 且 \(len(A_i) <= R_i\), \(A_i\)为从a到z的26个字母. ...

  3. 记一次小米手机安装Google Play(其他手机类似)

    记一次小米手机安装Google Play(其他手机类似) 最近换了一款小米10青春版,性价比很高,对于开发者而言,手机自带商店的软件内容往往不能满足需求,而需要单独定制习惯性的APP,博主通过最近的尝 ...

  4. Ubuntu16安装Caffe+Python3缺少libboost

    如果在/usr/lib/x86_64-linux-gnu中找到libboost_python-py3.5.so, 则 sudo ln -s libboost_python-py3.5.so libbo ...

  5. matplotlib 图标显示中文

    matplotlib 显示中文 Method_1: # 添上: plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签 plt.rcPara ...

  6. CSS 检测 IE 浏览器

    CSS 检测 IE 浏览器 <!--[if IE]> <link href="ie.css" rel="stylesheet"> < ...

  7. Twitter 分享

    Twitter 分享 Twitter Share API https://twitter.com/intent/tweet?url= &text= demo ?url= https://www ...

  8. yarn & uninstall global & yarn global remove

    yarn uninstall global yarn global remove https://yarnpkg.com/lang/en/docs/cli/remove/ https://yarnpk ...

  9. shit 环信 IM SDK & IM SDK & web

    shit 环信 IM SDK & IM SDK & web 环信 IM SDK, 采坑大全 自己写 UI appkey 是否正确 password 是字符串,不是 数字 HTTPS 是 ...

  10. Mybatis-03 配置解析

    Mybatis-03 配置解析 配置解析 1.核心配置文件 mybatis-config.xml: configuration(配置) properties(属性) settings(设置) type ...