一、题目

  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. windows cmd 查看远程连接端口

    查看远程端口号 Cmd tasklist  /svc 在输出的内容中查找svchost.exe进程下termservice服务对应的PID,在此查看的PID为:276 然后输入命令:netstat   ...

  2. 编写一个c函数,该函数给出一个字节中被置为1的位的个数

    请编写一个c函数,该函数给出一个字节中被置为1的位的个数 #include <stdio.h> void fun(char ch) { int i; int temp; int count ...

  3. C++ part9

    1.静态多态和动态多态 静态多态:函数重载,模板.编译期间完成. 动态多态:虚函数.运行期间实现. 2.模板的实现和优缺点 函数模板的代码并不能直接编译成二进制代码,而是要实例出一个模板实例.写了模板 ...

  4. LOJ6283 数列分块入门 7 (分块 区间加/乘)题解

    题意:区间加,区间乘,单点询问 思路:假设一个点为a,那么他可以表示为m * a + sum,所以区间加就变为m * a + sum + sum2,区间乘变为m * m2 * a + sum * m2 ...

  5. cobaltstrike的使用

    0x01 介绍 Cobalt Strike是一款渗透测试神器,常被业界人称为CS神器.Cobalt Strike已经不再使用MSF而是作为单独的平台使用,它分为客户端与服务端,服务端是一个,客户端可以 ...

  6. volatile的内存屏障的坑

    请看下面的代码并尝试猜测输出: 可能一看下面的代码你可能会放弃继续看了,但如果你想要彻底弄明白volatile,你需要耐心,下面的代码很简单! 在下面的代码中,我们定义了4个字段x,y,a和b,它们被 ...

  7. YouTube 视频下载工具

    YouTube 视频下载工具 我不生产视频,只是优秀视频的搬运工! YouTube-dl https://github.com/search?q=youtube-dl https://github.c ...

  8. TypeScript enum 枚举实现原理

    TypeScript enum 枚举实现原理 反向映射 https://www.typescriptlang.org/docs/handbook/enums.html enum Direction { ...

  9. rename github

    rename GitHub github repo rename xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!

  10. how to open a terminal in finder folder of macOS

    how to open a terminal in finder folder of macOS shit service demo refs https://lifehacker.com/launc ...