Codeforces Round #376 (Div. 2) F. Video Cards 数学 & 暴力
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 数学 & 暴力的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)
题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...
- Codeforces Round #585 (Div. 2) A. Yellow Cards(数学)
链接: https://codeforces.com/contest/1215/problem/A 题意: The final match of the Berland Football Cup ha ...
- Codeforces Round #485 (Div. 2) F. AND Graph
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...
- Codeforces Round #486 (Div. 3) F. Rain and Umbrellas
Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- Codeforces Round #501 (Div. 3) F. Bracket Substring
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...
- Codeforces Round #499 (Div. 1) F. Tree
Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...
- 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 ...
随机推荐
- 剑指offer12 打印从1到N位的所有数字,处理大整数情况
/** * */ package jianzhioffer; /** * @Description 输入n位数,输出0-N的所有数 * @author liutao * @data 2016年4月22 ...
- codeforces 659B B. Qualifying Contest(水题+sort)
题目链接: B. Qualifying Contest time limit per test 1 second memory limit per test 256 megabytes input s ...
- 集训Day13
我这个肥宅一点都不快乐嘤嘤嘤 bzoj3456 求n个点的无向简单连通图的个数 我们可以用容斥推出递推式 首先我们令为 于是有 这样就是可以用CDQ分治解决的一类递推式了 不是那么明显的变形一下得到 ...
- 「UVA11181」 Probability|Given(概率
题意翻译 有n个人要去买东西,他们去买东西的概率为p[i]. 现在得知有r个人买了东西,在这种条件下,求每个人买东西的概率. 感谢@s_r_f 提供翻译 题目描述 PDF 输入输出格式 输入格式: 输 ...
- 【Python】python2.7 安装配置OpenCV2
环境:Ubuntu16.04 anaconda Python2.7 opencv2.4.13 安装opencv后 import cv2 遇到错误信息: No module named cv2 安装op ...
- python script
1.tab键自动补全(每次导入时要将脚本的路径加入到sys.path中) import sysimport readlineimport rlcompleterimport atexitimport ...
- C++ 创建文件的方法
CString getPath(){ CTime time = CTime::GetCurrentTime(); CString t = time.Format(_T("%Y%m%d%H%M ...
- 解决CentOS 7安装zabbix 3.0 无法启动zabbix-server的问题[segfault at 18 ip 00007f78842b4bd0 sp 00007fff1995a818 error 4 in libpthread-2.17.so[7f78842ab000+16000]]
解决CentOS 7安装zabbix 3.0 无法启动zabbix-server的问题 [root@localhost sbin]# service zabbix-server start Redir ...
- 前端PHP Session的实例
登陆例子:(请注意一定要自己敲一遍,不要CV大法) 首先上一下成果图,激起同学们写的欲望,登录页如下: 点击登陆之后如下: 说明哦了,么问题.接下来自己实现一下. 首先数据库信息: 新建一个名为 l ...
- Python3解leetcode Maximum Subarray
问题描述: Given an integer array nums, find the contiguous subarray (containing at least one number) whi ...