Educational Codeforces Round 34 (Rated for Div. 2) D. Almost Difference(高精度)

来源:互联网 发布:excel找两列不同的数据 编辑:程序博客网 时间:2024/06/05 19:01

题目链接:http://codeforces.com/contest/903/problem/D


题目不难,按每个元素算贡献就好了,就是会爆long long,学习一下py的写法


代码:

from collections import Countern = input()a = map(int, raw_input().split())s = 0c = Counter()for i in xrange(n):    s += c[a[i] + 1] - c[a[i] - 1] + a[i] * (2 * i + 1 - n)    c[a[i]] += 1print(s)


阅读全文
0 0