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 ...
随机推荐
- POJ3417Network(LCA+树上查分||树剖+线段树)
Yixght is a manager of the company called SzqNetwork(SN). Now she's very worried because she has jus ...
- ACM学习历程——HDU2227 Find the nondecreasing subsequences(线段树 && dp)
Description How many nondecreasing subsequences can you find in the sequence S = {s1, s2, s3, ...., ...
- js将时间转换为时间戳
转自http://zhidao.baidu.com/link?url=jwmRLUKIC92fNeS1l8PuZltmZIN--LJFtKd9G6SYEjFfCu_pFGyXsh54txzv22E0g ...
- 主备角色switch
理论知识:Switchover 切换允许primary 和一个备库进行切换,并且这种切换没有数据丢失. 前提条件: 1) 主备库相关参数 fal_client.fal_server .standby_ ...
- Ubuntu 重启命令
重启命令: 1.直接reboot 2.shutdown -r now 这两种都是立刻重启 3.shutdown -r 大概30秒后会重启 关机命令:1.halt 立刻关机2.poweroff 立刻 ...
- javascript getAttribute
var nodes = document.getElementsByTagName("script"); var node = nodes[nodes.length - 1]; v ...
- day12Session案例 JSP
2 Session案例 用户登录场景 package gz.itcast; import java.io.IOException; import java.io.PrintWriter; import ...
- Java之匿名类讲解
参考https://blog.csdn.net/jiaotuwoaini/article/details/51542059 匿名类,正如名字一样在java中没有名字标识的类,当然了编译后还是会安排一个 ...
- 数据库中rs("ABC")与rs.Fields("ABC").value的差别(Rs是RecordSet对象)
透过RecordSet取得数据的时候我们要将数据显示出来时,假设字段名称是ABCABCX = rs("ABC")对于RecordSet来说....是把ABC这个[Fileds对象] ...
- 利用URL重写隐藏复杂的URL
第一步:模拟映射页面 我们想在一个页面上点击guid.html链接,跳转到比较复杂URL的guid_{492f3e0b-848e-11da-9550-00e08161165f}.html页面.即定义一 ...