由于下午硬钢树套树和大力颓废就没补完
C:我傻逼比赛时没做出来。。。就是排个序然后算贡献
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 300010, mod = 1000000007; int n; ll ans, t = 1; ll a[N], bin[N]; bool cp(int i, int j) { return i < j; } int main() { scanf("%d", &n); bin[0] = 1; for(int i = 1; i <= n; ++i) { scanf("%lld", &a[i]); t = t * 2ll % mod; bin[i] = (bin[i - 1] + t) % mod; } sort(a + 1, a + n + 1, cp); for(int i = 2; i <= n; ++i) ans = (ans + a[i] % mod * bin[i - 2] % mod) % mod; for(int i = n - 1; i; --i) ans = ((ans - a[i] % mod * bin[n - i - 1] % mod) % mod + mod) % mod; printf("%lld\n", ans); return 0; }
时间: 2024-12-25 23:20:13