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) 二.分析 相比于简单版本,它的复杂地方在于对于不同长度,可能对每个点的贡献可能是有差异的. 但 ...
随机推荐
- Hexo准备---Node.js、Vue
Hexo准备---Node.js.Vue 安装node.js 1.下载node 配置node.js环境官网下载,一直next就好,非常方便. 下载官网: http://nodejs.cn/downlo ...
- ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)
cmd mysql -h localhost -u root -p r然后报错 ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost ...
- Git使用出现Automatic merge failed; fix conflicts and then commit the result.解决方法
产生原因 首先这个问题产生的原因是因为你git pull 的时候会分为两步,第一步先从远程服务器上拉下代码,第二步进行merge,但是merge时候失败了就会产生上述问题. 解决方法: 丢弃本地提交, ...
- codefoeces 864B
B. Polycarp and Letters time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 多线程(四) AQS底层原理分析
J.U.C 简介 Java.util.concurrent 是在并发编程中比较常用的工具类,里面包含很多用来在并发 场景中使用的组件.比如线程池.阻塞队列.计时器.同步器.并发集合等等.并 发包的作者 ...
- taro table component
taro table component https://juejin.im/post/5d901696f265da5b926bbcaa https://taro-ext.jd.com/search? ...
- POST 非幂等
POST 非幂等 HTTP幂等方法,是指无论调用这个url多少次,都不会有不同的结果的HTTP方法; 也就是不管你调用1次还是调用100次,1000次,结果都是一样的(前提是服务器端的数据没有被人为手 ...
- 万链互联时代,NGK DeFi项目如何在牛市中崭露头角!
众所周知,中心化交易所存在技术风险.道德风险与法律风险.去中心化交易所像是NGK以其匿名性.安全性.私钥独立掌控的特点,弥补了中心化交易所的不足,我们看到Uniswap日成交量均超过1亿美元,甚至接近 ...
- Python算法_盛最多水的容器(04)
给你 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线, ...
- Django Admin后台管理功能使用+二次开发
一 使用环境 开发系统: windows IDE: pycharm 数据库: msyql,navicat 编程语言: python3.7 (Windows x86-64 executable in ...