Codeforces Round #415 (Div. 2)C
反正又是一个半小时没做出来。。。
先排序,然后求和,第i个和第j个,f(a)=a[j]-a[i]=a[i]*(2^(j-i-1))因为从j到i之间有j-i-1个数(存在或者不存在有两种情况)
又有a[i+k]-a[i]=a[n]+a[n-1]+...+a[n-k]-a[k+1]-...-a[1]
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=,inf=; ll a[N],sum[N],p[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie();
ll n;
cin>>n;
p[]=;
for(ll i=;i<=n;i++)
{
p[i]=p[i-]<<;
p[i]%=mod;
}
sum[]=;
for(ll i=;i<=n;i++)cin>>a[i];
sort(a+,a++n);
for(ll i=;i<=n;i++)sum[i]=(sum[i-]+a[i])%mod;
ll ans=;
for(ll i=;i<n-;i++)
{
ans+=(p[i]*(sum[n]+mod-sum[i+]+mod-sum[n-i-])%mod)%mod;
ans%=mod;
}
cout<<ans<<endl;
return ;
} /*
a[i]=sum[n]-sum[n-i-1]-sum[i]
*/
Codeforces Round #415 (Div. 2)C的更多相关文章
- Codeforces Round #415 (Div. 2)(A,暴力,B,贪心,排序)
A. Straight «A» time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...
- Codeforces Round#415 Div.2
A. Straight «A» 题面 Noora is a student of one famous high school. It's her final year in school - she ...
- Codeforces Round #415(Div. 2)-810A.。。。 810B.。。。 810C.。。。不会
CodeForces - 810A A. Straight «A» time limit per test 1 second memory limit per test 256 megabytes i ...
- Codeforces Round #415 Div. 1
A:考虑每对最大值最小值的贡献即可. #include<iostream> #include<cstdio> #include<cmath> #include< ...
- Codeforces Round #415 (Div. 2) A B C 暴力 sort 规律
A. Straight «A» time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #415 (Div. 2) C. Do you want a date?
C. Do you want a date? 2 seconds 256 megabytes Leha decided to move to a quiet town Vičkopolis, ...
- Codeforces Round #415 (Div. 2) B. Summer sell-off
B. Summer sell-off time limit per test 1 second memory limit per test 256 megabytes Summer hol ...
- Codeforces Round #415 (Div. 2) 翻车啦
A. Straight «A» time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #415 (Div. 1) (CDE)
1. CF 809C Find a car 大意: 给定一个$1e9\times 1e9$的矩阵$a$, $a_{i,j}$为它正上方和正左方未出现过的最小数, 每个询问求一个矩形内的和. 可以发现$ ...
随机推荐
- XPipe 解决什么问题
x-pipe/README.md at master · ctripcorp/x-pipe https://github.com/ctripcorp/x-pipe/blob/master/README ...
- Jscript运行时错误:没有权限
问题:我在页面A中放了一个iframe ,然后在iframe 的子页面中调用主页面中的JavaScript函数,结果报错Jscript运行时错误:没有权限 原因有2: 1. 是逻辑错误,比如先关闭了i ...
- Openstack(五)Memcache- repcached集群
5.1.1下载Memcache- repcached并解压 # wget http://downloads.sourceforge.net/repcached/memcached-1.2.8-repc ...
- Linux下编译安装PHP扩展redis
[Redis] 先安装tcl: yum install tcl [下载和安装] 官网http://redis.io/ 下载最新的稳定版本,这里是3.2.0, 然后解压文件并进入. $ sudo ta ...
- Spark checkpoint机制简述
本文主要简述spark checkpoint机制,快速把握checkpoint机制的来龙去脉,至于源码可以参考我的下一篇文章. 1.Spark core的checkpoint 1)为什么checkpo ...
- java基础语法 数组
数组是相同数据类型元素的集合 数组本身是引用数据类型,即对象.但是数组可以存储基本数据类型,也可以存储引用数据类型. 在java中如果想要保存一组基本类型的数据,使用数组:如果想保存一组对象或者其 ...
- 6.1 Controllers -- Introduction
一.Controllers 1. 在Ember.js中,controllers允许你使用展现逻辑装饰你的models.通常,models将会有保存到服务器的属性,然而controllers将会有不需要 ...
- kafka环境安装
源码包下载: http://archive.apache.org/dist/kafka/1.0.0/ 集群环境: master 192.168.1.99 slave1 192.168.1.100 sl ...
- P1757 通天之分组背包 / hdu1712 ACboy needs your help (分组背包入门)
P1757 通天之分组背包 hdu1712 ACboy needs your help hdu1712题意:A[i][j]表示用j天学习第i个课程能够得到A[i][j]的收益,求m天内获得的收益最大值 ...
- Python3 pandas用法大全
Python3 pandas用法大全 一.生成数据表 1.首先导入pandas库,一般都会用到numpy库,所以我们先导入备用: import numpy as np import pandas as ...