Codeforces Round #574 (Div. 2) E. 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 【单调队列】的更多相关文章
- Codeforces Round #574 (Div. 2) E.OpenStreetMap
题目链接 题目的意思就是给你一个矩阵你要求给定子矩阵的最小值的和 单调队列扫两边即可 #include <bits/stdc++.h> #define ll long long #defi ...
- Codeforces Round #574 (Div. 2)
目录 Contest Info Solutions A. Drinks Choosing B. Sport Mafia C. Basketball Exercise D1. Submarine in ...
- Codeforces Round #574 (Div. 2) A~E Solution
A. Drinks Choosing 有 $n$ 个人,每个人各有一种最喜欢的饮料,但是买饮料的时候只能同一种的两个两个买(两个一对) 学校只打算卖 $\left \lceil \frac{n}{2} ...
- Codeforces Round #574 (Div. 2)题解
比赛链接 传送门 A题 题意 \(n\)个人每个人都有自己喜欢喝的\(vechorka\)口味,现在给你\(\lceil n/2\rceil\)箱\(vechorka\),每箱有两瓶,问最多能有多少个 ...
- Codeforces Round #622 (Div. 2)C(单调栈,DP)
构造出的结果一定是一个单峰/\这种样子的 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ...
- 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 ...
- Codeforces Round #574 (Div. 2)——C. Basketball Exercise(简单DP)
题目传送门 题意: 输入n,给出两组均为 n个数字的数组a和b,轮流从a和b数组中取出一个数字,要求严格按照当前所选数字的数组下标比上一个所选数字的数组下标更大,计算能够取出的数字加起来的总和最大能为 ...
- Codeforces Round #574 (Div. 2)补题
A. Drinks Choosing 统计每种酒有多少人偏爱他们. ki 为每种酒的偏爱人数. 输出ans = (n + 1)/2 > Σki / 2 ? (n + 1)/2 - Σki / ...
- Codeforces Round #574 (Div. 2) D2. Submarine in the Rybinsk Sea (hard edition) 【计算贡献】
一.题目 D2. Submarine in the Rybinsk Sea (hard edition) 二.分析 相比于简单版本,它的复杂地方在于对于不同长度,可能对每个点的贡献可能是有差异的. 但 ...
随机推荐
- 4.安装fluentd用于收集集群内部应用日志
作者 微信:tangy8080 电子邮箱:914661180@qq.com 更新时间:2019-06-13 11:02:14 星期四 欢迎您订阅和分享我的订阅号,订阅号内会不定期分享一些我自己学习过程 ...
- 【非原创】LightOj 1248 - Dice (III)【几何分布+期望】
学习博客:戳这里 题意:有一个 n 面的骰子,问至少看到所有的面一次的所需 掷骰子 的 次数的期望: 第一个面第一次出现的概率是p1 n/n; 第二个面第一次出现的概率是p2 (n-1)/n; 第三个 ...
- cin 与 getline
cin空格截断 getline(cin,s) 换行结束 ....太愚蠢了
- 如何将多个 Apple 设备中保存在 iCloud 里面密码同步
如何将多个 Apple 设备中保存在 iCloud 里面密码同步 iCloud 钥匙串 密码同步 数据迁移 iOS iCloud 钥匙串会记住一些信息,因此您就无需记忆这些信息. 它会在您批准的任何设 ...
- 前端 vs 后端
前端 vs 后端 前端与后端: 有什么区别? 前端和后端是计算机行业中最常用的两个术语. 在某种程度上,它们成了流行语. 它们决定了您作为软件开发人员所从事的工作类型,所使用的技术以及所获得的收入. ...
- Open Collective
Open Collective Open Collective is an online funding platform for open and transparent communities. ...
- leetcode solution cracked tutorial
leetcode solution cracked tutorial problemset https://leetcode.com/problemset/all/ Top Interview Que ...
- Web Vitals
Web Vitals https://www.youtube.com/watch?v=2k1QbgLAFdI&feature=youtu.be $ npm i -S web-vitals ht ...
- D language
D language https://en.wikipedia.org/wiki/D_(programming_language) Dart https://dlang.org/ flutter fr ...
- flutter 插件调用callback函数
dart plugin class TestLib { static MethodChannel _channel = const MethodChannel('test_lib') ..setMet ...