http://codeforces.com/contest/731/problem/F

注意到一个事实,如果你要找一段区间中(从小到大的),有多少个数是能整除左端点L的,就是[L, R]这样。那么,很明显,把这个区间分段。分成[L, 2 * L - 1],因为这段区间中,都不大于等于L的两倍,这样就使得这段区间的贡献就是sum_number * L了。

就是中间有多少个数,每个数贡献一个L值。然后到枚举[2 * L, 3 * L - 1]这段区间,贡献的值就是sum_number * (2 * L)了。
因为2 * L是肯定能% L == 0的,所以加起来所有区间的贡献,就是以L作为起点的贡献。

所以就是预处理一下前缀和就OK了。book[i]表示<= i这个元素有多少个。

这样的复杂度是maxn + maxn / 2 + maxn / 3 + ....的,就是nlogn

当然还是有些边界要处理的。因为数值最大是200000,所以要预处理到2  * maxn

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = + ;
LL book[ * maxn];
bool has[ * maxn];
void work() {
int n;
cin >> n;
for (int i = ; i <= n; ++i) {
int a;
scanf("%d", &a);
book[a]++;
has[a] = true;
}
for (int i = ; i <= * maxn - ; ++i) {
book[i] += book[i - ];
}
LL ans = -inf;
for (int i = ; i <= maxn - ; ++i) {
if (!has[i]) continue;
LL t = ;
for (int j = i; j <= maxn - ; j += i) {
t += (book[j + i - ] - book[j - ]) * j;
}
ans = max(ans, t);
}
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
work();
return ;
}

Codeforces Round #376 (Div. 2) F. Video Cards 数学 & 暴力的更多相关文章

  1. Codeforces Round #376 (Div. 2) F. Video Cards 数学,前缀和

    F. Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. Codeforces Round #376 (Div. 2) F. Video Cards —— 前缀和 & 后缀和

    题目链接:http://codeforces.com/contest/731/problem/F F. Video Cards time limit per test 1 second memory ...

  3. Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)

    题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...

  4. Codeforces Round #585 (Div. 2) A. Yellow Cards(数学)

    链接: https://codeforces.com/contest/1215/problem/A 题意: The final match of the Berland Football Cup ha ...

  5. Codeforces Round #485 (Div. 2) F. AND Graph

    Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...

  6. Codeforces Round #486 (Div. 3) F. Rain and Umbrellas

    Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  7. Codeforces Round #501 (Div. 3) F. Bracket Substring

    题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...

  8. Codeforces Round #499 (Div. 1) F. Tree

    Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...

  9. Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索

    Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx ...

随机推荐

  1. Servlet_03_部署描述符

    二.参考文档 1.Servlet 3.0 之 部署描述符 2.web.xml配置详解 部署描述符文件

  2. c++类之间的关系

    我们知道,表达方式分为很多种,对于同一种事物,比如爱情,画家用图画和色彩表达爱恋:音乐家用音符和节奏表达喜爱之情,作家用文字表现爱慕. 而程序员怎么办? 程序员构建类,用类来表达单身之苦.因此,类就是 ...

  3. (Nginx + Gunicorn) 时 nginx 400 request line is too large (4360 4094)

    查看nginx下面两个参数 值是否满足 client_header_buffer_size 512k;large_client_header_buffers 4 512k; 满足依然出现 如果ngin ...

  4. 【LeetCode】017. Letter Combinations of a Phone Number

    题目: Given a digit string, return all possible letter combinations that the number could represent. A ...

  5. 组播基本概念、IGMP、IGMP监听学习笔记

    前言 一直对组播这个概念迷迷糊糊,特别是交换机处理组播的方式,非常想搞懂但是懒癌发作.这几天终于耐心地看了下有关组播的资料,大致了解了一下同一广播域内组播的相关知识.组播占了计算机网络的一大部分,特别 ...

  6. RDA项目打包

    注意APP的编译搭建: ./aps/Makefile.toolchain //ccoption path的设定 ./aps/rules.mak //统一的编译规则 MAKE -C 1.TOOLS的可执 ...

  7. makefile 使用【转载】

    该篇文章为转载,是对原作者系列文章的总汇加上标注. 支持原创,请移步陈浩大神博客: http://blog.csdn.net/haoel/article/details/2886 makefile很重 ...

  8. SpringMVC 全注解实现 (1) servlet3.0以上的容器支持

    一. Spring MVC入门 1.1 request的处理过程 用户每次点击浏览器界面的一个按钮,都发出一个web请求(request).一个web请求的工作就像一个快递员,负责将信息从一个地方运送 ...

  9. css 中visibility:hidden和display:none有什么区别呢

    <div style="width:100px;height:100px;background:red;visibility:hidden"></div>/ ...

  10. vue 之 折线图挤压

    当tab标签栏变动时,echarts图会发生挤,这种情况,发现是html容器的width=100%这个设置,变成了width=100px. 解决方式: 1.设置一个最小宽度,获取width的值,当这个 ...