一、题目

  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 【数学+分块】的更多相关文章

  1. 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 \( ...

  2. Educational Codeforces Round 69 (Rated for Div. 2) E. Culture Code

    Educational Codeforces Round 69 (Rated for Div. 2) E. Culture Code 题目链接 题意: 给出\(n\)个俄罗斯套娃,每个套娃都有一个\( ...

  3. Educational Codeforces Round 69 (Rated for Div. 2)

                                                                                                  A. DIY ...

  4. Educational Codeforces Round 69 (Rated for Div. 2) C. Array Splitting 水题

    C. Array Splitting You are given a sorted array

  5. Educational Codeforces Round 69 (Rated for Div. 2) A~D Sloution

    A. DIY Wooden Ladder 题意:有一些不能切的木板,每个都有一个长度,要做一个梯子,求梯子的最大台阶数 做梯子的木板分为两种,两边的两条木板和中间的若干条台阶木板 台阶数为 $k$ 的 ...

  6. 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[ ...

  7. Educational Codeforces Round 69 (Rated for Div. 2) C. Array Splitting (思维)

    题意:给你一个长度为\(n\)的升序序列,将这个序列分成\(k\)段,每一段的值为最大值和最小值的差,求\(k\)段值的最小和. 题解:其实每一段的最大值和最小值的差,其实就是这段元素的差分和,因为是 ...

  8. 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)的个数,那么实 ...

  9. Educational Codeforces Round 130 (Rated for Div. 2) C. awoo's Favorite Problem

    https://codeforc.es/contest/1697/problem/C 因为规则中,两种字符串变换都与'b'有关,所以我们根据b的位置来进行考虑: 先去掉所有的'b',如果两字符串不相等 ...

随机推荐

  1. java-GUI编程学习总结

    狂神说java-GUI编程学习总结 1.简介 2.AWT 2.1.实现如图1-2 (1)面向过程写法 (2)内部类写法 (3)完全改造成面向对象 3.Swing 3.1.鼠标花点 3.2.弹窗 3.3 ...

  2. struct 和 class的区别

    struct和class如果按照在C的时代,还是有很大差别的. c中struct的定义如下: struct  结构名 {   成员表 }: 因为struct是一种数据类型,那么就肯定不能定义函数,所以 ...

  3. 洛谷p1198 最大数

    #include <iostream> #include <cstdio> #include <algorithm> using namespace std; in ...

  4. ysoserial Commons Collections2反序列化研究

    Apache Commons Collections2反序列化研究 环境准备 JDK 1.7 Commons Collections 4.0 javassit 前置知识 PriorityQueue() ...

  5. javascript questions & code review

    javascript questions & code review refs https://github.com/learning-js-by-reading-source-codes/j ...

  6. Creative Commons : CC (知识共享署名 授权许可)

    1 https://creativecommons.org/      Keep the internet creative, free and open. Creative Commons help ...

  7. How to change Linux Terminal display username

    How to change Linux Terminal display username 如何更改 Linux Terminal 显示的用户名 (base) ➜ ~ whoami xgqfrms-m ...

  8. browser parse CSS style order

    browser parse CSS style order 浏览器解析 CSS style 的顺序 从右到左 https://juejin.im/entry/5a123c55f265da432240c ...

  9. 小程序 in action

    小程序 in action https://github.com/xgqfrms/xcx-taro taro https://taro-docs.jd.com/taro/docs/README.htm ...

  10. nodejs 在windows10中设置动态(视频)壁纸

    github 项目地址 node版本 λ node -v v12.16.2 main.js const ffi = require("@saleae/ffi"); const ch ...