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

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. using namespace std;
  7. #define inf (0x3f3f3f3f)
  8. typedef long long int LL;
  9.  
  10. #include <iostream>
  11. #include <sstream>
  12. #include <vector>
  13. #include <set>
  14. #include <map>
  15. #include <queue>
  16. #include <string>
  17. const int maxn = + ;
  18. LL book[ * maxn];
  19. bool has[ * maxn];
  20. void work() {
  21. int n;
  22. cin >> n;
  23. for (int i = ; i <= n; ++i) {
  24. int a;
  25. scanf("%d", &a);
  26. book[a]++;
  27. has[a] = true;
  28. }
  29. for (int i = ; i <= * maxn - ; ++i) {
  30. book[i] += book[i - ];
  31. }
  32. LL ans = -inf;
  33. for (int i = ; i <= maxn - ; ++i) {
  34. if (!has[i]) continue;
  35. LL t = ;
  36. for (int j = i; j <= maxn - ; j += i) {
  37. t += (book[j + i - ] - book[j - ]) * j;
  38. }
  39. ans = max(ans, t);
  40. }
  41. cout << ans << endl;
  42. }
  43.  
  44. int main() {
  45. #ifdef local
  46. freopen("data.txt","r",stdin);
  47. #endif
  48. work();
  49. return ;
  50. }

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. oracle数据库复习(1)

    数据库中的专业术语: 表:在数据库中存放数据所用的表 视图:数据库中的虚拟表.在视图中存放的是从数据表中查询出来的纪录 存储过程:存储过程是由SQL语句和控制流语句组成的代码块.存储过程在开发软件时, ...

  2. Go丨语言学习笔记--switch

    Java语言与Go语言的switch对比 Go语言 switch str { case "yes" : do something ... case "no" d ...

  3. CodeForces Div1: 995 D. Game(数学期望)

    Allen and Bessie are playing a simple number game. They both know a function f:{0,1}n→Rf:{0,1}n→R, i ...

  4. poj 2719 Faulty Odometer

    Description You are given a car odometer which displays the miles traveled as an integer. The odomet ...

  5. ubuntu svn 常用命令

    1.svn svn update 更新 新增文件或文件夹并提交svn add "sss" test.py testw.pysvn add "dir" dir_p ...

  6. 洛谷【P3437】[POI2006]TET-Tetris 3D

    浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 浅谈标记永久化:https://www.cnblogs.com/AKMer/p/1013 ...

  7. JSP的优势 和劣势 与php的比较

    一 jsp的 优势 与劣势 由于JSP页面的内置脚本语言是基于Java编程语言的,而且所有的JSP页面都被编译成为Java Servlet,JSP页面就具有Java技术的所有好处,包括健壮的存储管理和 ...

  8. 使用二次封装的openStack发行版本网卡至少有2个

  9. JavaScript高级程序设计学习笔记第十四章--表单

    1.在 HTML 中,表单是由<form>元素来表示的,而在 JavaScript 中,表单对应的则是 HTMLFormElement 类型. HTMLFormElement 继承了 HT ...

  10. monkey无规则压力测试

    例:monkey -p com.tencent.mtaexample -s 23  --throttle 100 --ignore-crashes --ignore-timeouts -v -v -v ...