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. Ubuntu16.04上安装arm-linux-gcc4.4.3

    一.首先下载arm-linux-gcc-4.4.3.tar.gz安装包,安装包地址: http://www.cr173.com/soft/42654.html 二.解压安装包: sudo tar -z ...

  2. css实现下拉列表

    像上面的要想实现 Hover 标题时  内容区下拉的效果,一般是要用js实现: 先获取内容区的高度,由于内容区刚开始可能是隐藏的,那么怎么才能获取其高度呢?方法是先给其元素设置绝对定位并把位置保持和之 ...

  3. python 之gc(回收机制)--garbage collection(GC垃圾回收)

    ######################引用计数######################### 引用计数:python 当中一种用来解决垃圾回收的策略之一 char 1个字节(2**8) in ...

  4. Spring 3.1新特性之三:Spring支持Servlet 3.0(待补充)

    高效并发是JDK 1.6的一个重要主题,HotSpot虚拟机开发团队在这个版本上花费了大量的精力去实现各种锁优化技术,如适应性自旋(Adaptive Spinning).锁削除(Lock Elimin ...

  5. php file_get_contents超时处理

    因为要用php去向我的虚拟主机管理系统发送开通空间等的请求,需要Post传值,由于开通空间过程很慢,同时需要延时处理.以下找到了一下file_get_contents的超时处理,网上有人用2个方法解决 ...

  6. 爬虫之BeautifulSoup, CSS

    1. Beautiful Soup的简介 2. Beautiful Soup 安装 可以利用 pip 或者 easy_install 来安装,以下两种方法均可 easy_install beautif ...

  7. layer常用方法

    弹出层layer的使用 弹出层layer的使用 Intro layer是一款web弹层组件,致力于服务各个水平段的开发人员.layer官网:http://layer.layui.com/ layer侧 ...

  8. BDBR vs BDPSNR 计算方法 (转载)

    转自:http://blog.csdn.net/menyangyang/article/details/42874575

  9. 初识Kotlin之集合

    Kotlin的集合是让我为之心动的地方,丰富的高阶函数帮助我们高效开发.今天介绍Kotlin的基础集合用法.获取集合元素的函数.过滤元素的函数.元素排序的函数.元素统计的函数.集合元素映射的函数.集合 ...

  10. 记一次前端面试~终于拿到理想中的offer!

    2019年已经过去一半,终于拿到一直想去的公司offer,也算是实现了今年的一个小目标. 由于这家公司是我从去年到现在最想去的公司,本次换工作一直没有投,希望先积累下面试经验再投. 没有想到居然先在b ...