Educational Codeforces Round 69 (Rated for Div. 2) D. Yet Another Subarray Problem 【数学+分块】
一、题目
D. Yet Another Subarray Problem
二、分析
公式的推导时参考的洛谷聚聚们的推导
重点是公式的推导,推导出公式后,分块是很容易想的。但是很容易写炸。
1 有些地方容易溢出,这和设置的无穷大的值的大小也有关。
2 如果每次确定了边界$r$,那么在枚举$m$的余数的情况时,一定注意到比$r$大的还不能枚举。
三、AC代码
1 #include <bits/stdc++.h>
2
3 using namespace std;
4 #define Min(a, b) ((a)<(b)?(a):(b))
5 #define Max(a, b) ((a)>(b)?(a):(b))
6 typedef long long ll;
7 const int maxn = 3e5 + 13;
8 const ll inf = 1e15 ;
9 int n, m;
10 ll k;
11 int a[maxn];
12 ll sum[maxn];
13 ll D[maxn];
14 ll Dmin[15];
15
16 int main()
17 {
18 //freopen("input.txt", "r", stdin);
19 while(scanf("%d %d %I64d", &n, &m, &k) != EOF)
20 {
21 fill(Dmin, Dmin + 11, inf);
22 sum[0] = 0;
23 for(int i = 1; i <= n; i++)
24 {
25 scanf("%d", &a[i]);
26 sum[i] = sum[i - 1] + a[i];
27 D[i] = sum[i] - k * (i / m);
28 }
29 ll ans = 0;
30 Dmin[0] = 0;
31 for(int i = 1; i <= n; i++)
32 {
33 ll res = -inf;
34 for(int j = 0; j < m; j++)
35 {
36 int f = ceil(1.0 * ( (i % m) - j) / m);
37 res = Max(res, D[i] - Dmin[j] - k * f);
38 }
39 Dmin[i % m] = Min(D[i], Dmin[i % m]);
40 ans = Max(res, ans);
41 }
42 printf("%lld\n", ans);
43 }
44
45
46 }
Educational Codeforces Round 69 (Rated for Div. 2) D. Yet Another Subarray Problem 【数学+分块】的更多相关文章
- Educational Codeforces Round 69 (Rated for Div. 2) D. Yet Another Subarray Problem 背包dp
D. Yet Another Subarray Problem You are given an array \(a_1, a_2, \dots , a_n\) and two integers \( ...
- Educational Codeforces Round 69 (Rated for Div. 2) E. Culture Code
Educational Codeforces Round 69 (Rated for Div. 2) E. Culture Code 题目链接 题意: 给出\(n\)个俄罗斯套娃,每个套娃都有一个\( ...
- Educational Codeforces Round 69 (Rated for Div. 2)
A. DIY ...
- Educational Codeforces Round 69 (Rated for Div. 2) C. Array Splitting 水题
C. Array Splitting You are given a sorted array
- Educational Codeforces Round 69 (Rated for Div. 2) A~D Sloution
A. DIY Wooden Ladder 题意:有一些不能切的木板,每个都有一个长度,要做一个梯子,求梯子的最大台阶数 做梯子的木板分为两种,两边的两条木板和中间的若干条台阶木板 台阶数为 $k$ 的 ...
- Educational Codeforces Round 69 (Rated for Div. 2)D(DP,思维)
#include<bits/stdc++.h>using namespace std;int a[300007];long long sum[300007],tmp[300007],mx[ ...
- Educational Codeforces Round 69 (Rated for Div. 2) C. Array Splitting (思维)
题意:给你一个长度为\(n\)的升序序列,将这个序列分成\(k\)段,每一段的值为最大值和最小值的差,求\(k\)段值的最小和. 题解:其实每一段的最大值和最小值的差,其实就是这段元素的差分和,因为是 ...
- Educational Codeforces Round 50 (Rated for Div. 2) F - Relatively Prime Powers(数学+容斥)
题目链接:http://codeforces.com/contest/1036/problem/F 题意: 题解:求在[2,n]中,x != a ^ b(b >= 2 即为gcd)的个数,那么实 ...
- Educational Codeforces Round 130 (Rated for Div. 2) C. awoo's Favorite Problem
https://codeforc.es/contest/1697/problem/C 因为规则中,两种字符串变换都与'b'有关,所以我们根据b的位置来进行考虑: 先去掉所有的'b',如果两字符串不相等 ...
随机推荐
- 鸟哥的linux私房菜——第七章学习(Linux 磁盘与文件系统管理)
1.1).文件系统特征 我们称呼一个可被挂载的数据为一个文件系统而不是一个分区! 文件系统通常会将这两部份的数据分别存放在不同的区块,权限与属性放置到 inode 中,至于实际数据则放置到 data ...
- redis字典
字典作为一种保存键值对的数据结构,在redis中使用十分广泛,redis作为数据库本身底层就是通过字典实现的,对redis的增删改查实际上也是构建在字典之上. 一.字典的结构
- GraphQL All In One
GraphQL All In One refs https://github.com/hasura/learn-graphql xgqfrms 2012-2020 www.cnblogs.com 发布 ...
- Generator function vs Async/Await
Generator function vs Async/Await generator async /await refs xgqfrms 2012-2020 www.cnblogs.com 发布文章 ...
- windows 10 remote desktop
windows 10 remote desktop https://support.microsoft.com/en-us/help/4028379/windows-10-how-to-use-rem ...
- node.js 如何处理一个很大的文件
node.js 如何处理一个很大的文件 思路 arraybuffer 数据分段 时间分片 多线程 web workers sevice workers node.js 如何处理一个很大的文件 http ...
- GitHub & GitHub Package Registry
GitHub & GitHub Package Registry npm https://github.blog/2019-05-10-introducing-github-package-r ...
- 2019 front-end job Interview
2019 front-end job Interview 2019 前端面试题 掘金 https://juejin.im/tag/面试 https://juejin.im/post/5c875791e ...
- qt QTimer 计时器
#include <QtCore> #include <QTimer> QTimer *timer; timer = new QTimer(this); connect(tim ...
- BTC暴涨市值仅次于亚马逊,NGK推出新人助力空投,直接免费送VAST!
数据显示,在谷歌搜索中,关键词"BTC"的全球搜索指数在过去一周达到满值100点.特斯拉"加持"下,比特币重启暴涨模式,最高报价48126美金单价,非小号数据显 ...