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',如果两字符串不相等 ...
随机推荐
- python函数传参
之前一直没有注意过该问题,在leetcode144中写递归发现该问题,不知道递归函数传参是指针还是引用. 参考:http://c.biancheng.net/view/2258.html 如果是不可变 ...
- codeforces 14D(搜索+求树的直径模板)
D. Two Paths time limit per test 2 seconds memory limit per test 64 megabytes input standard input o ...
- koa-router all in one
koa-router all in one holy shit , WTF, which is the true koa-router! MMP, 哪一个是正确的呀,fuck 找半天都晕了! koa- ...
- copyright@xgqfrms
copyright@xgqfrms copyright & seo ## refs *** <div> <a href="https://info.flagcoun ...
- flat array
flat array 已知如下数组: var arr = [ [1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 1 ...
- React & CSS Modules & CSS in JS
React & CSS Modules & CSS in JS https://codesandbox.io/s/css-modules-name-mangling-ck1eo CSS ...
- Android Studio 3.3.1 向avd模拟器发送本地文件
"工具栏/View/Tool Windows/Device File Pxplorer" 选择模拟器在找到对应的文件夹upload即可
- go-admin在线开发平台学习-1[安装、配置、启动]
项目介绍 go-admin 是一个中后台管理系统,基于(gin, gorm, Casbin, Vue, Element UI)实现.主要目的是为了让开发者更专注业务,减少重复代码的编写,节省时间,提升 ...
- Java中print、printf、println的区别
Java中print.printf.println的区别 区别 print:标准输出,但不换行,不可以空参: println:标准输出,但会自动换行,可以空参,可以看做:println()相当于pri ...
- C++算法代码——[TYVJ]单数?双数?
题目来自:http://218.5.5.242:9018/JudgeOnline/problem.php?id=1178 题目描述 Bessie那惨无人道的二年级老师搞了一个有 N (1 < ...