Codeforces Round #415 C. Do you want a date?

5G核心技术:N3与N4接口深度解析 5G网络中,N3和N4接口是实现用户数据传输的核心。N3接口是gNB与UPF之间的用户面通道,采用GTP-U协议封装数据,通过UDP/IP传输,确保低时延和业务隔离。N4接口是SMF与UPF之间的控制面链路,基于PFCP协议下发转发规则(FAR/TDR/QER/URR),实现精细化流量控制。二者协同工作:N4下发策略(如QoS、计费规则),N3执行数据转发,共同支持5G三大场景(eMBB/uRLLC/mMTC),体现控制与转发分离(CUPS)架构优势。 阅读详情

Do you want a date?
time limit per test 2 seconds
memory limit per test 256 megabytes

Description
Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to n computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on the same straight line, due to the reason that there is the only one straight street in Vičkopolis.

Let’s denote the coordinate system on this street. Besides let’s number all the hacked computers with integers from 1 to n. So the i-th hacked computer is located at the point xi. Moreover the coordinates of all computers are distinct.

Leha is determined to have a little rest after a hard week. Therefore he is going to invite his friend Noora to a restaurant. However the girl agrees to go on a date with the only one condition: Leha have to solve a simple task.

Leha should calculate a sum of F(a) for all a, where a is a non-empty subset of the set, that consists of all hacked computers. Formally, let’s denote A the set of all integers from 1 to n. Noora asks the hacker to find value of the expression . Here F(a) is calculated as the maximum among the distances between all pairs of computers from the set a. Formally, . Since the required sum can be quite large Noora asks to find it modulo 109 + 7.

Though, Leha is too tired. Consequently he is not able to solve this task. Help the hacker to attend a date.

Input
The first line contains one integer n (1 ≤ n ≤ 3·105) denoting the number of hacked computers.

The second line contains n integers x1, x2, …, xn (1 ≤ xi ≤ 109) denoting the coordinates of hacked computers. It is guaranteed that all xi are distinct.

Output
Print a single integer — the required sum modulo 1e9 + 7.

Examples
Input
2
4 7
Output
3
Input
3
4 3 1
Output
9

Note
There are three non-empty subsets in the first sample test:, and . The first and the second subset increase the sum by 0 and the third subset increases the sum by 7 - 4 = 3. In total the answer is 0 + 0 + 3 = 3.

There are seven non-empty subsets in the second sample test. Among them only the following subsets increase the answer: , , , . In total the sum is (4 - 3) + (4 - 1) + (3 - 1) + (4 - 1) = 9.

题目大意:给你一个非空数集,让你求他所有子集的最大值与最小值的和。

看到题目给你两秒钟,嗯,肯定不能暴力( _ _)ノ|
昨晚做这道题的时候想了半天,这东西肯定是有个啥规律的,不然肯定TLE啊。
自己在本子上写了几个例子,似乎发现了某种规律,那就是每个数字作为最大值的次数或是最小值的次数,与其在子集sort后的排序有关,得到了这一点,很快就能写出代码啦( ^ω^)

ps.虽然代码是写出来了,但是却犯了个巨严重的错误,我在读取a[i]的时候忘了加&啊啊啊啊啊啊啊啊,搞得我一行一行调试了半天才发现为啥一直RE

#include <bits/stdc++.h>
const int Max=500005;
#define mod 1000000000+7
using namespace std;
typedef long long ll;
ll cnt[Max];
ll a[Max];
ll sum=0;
int n;
int main()
{
    cnt[0]=1;
    for(int i=1;i<=400000;i++)
    {
        cnt[i]=cnt[i-1]*2;
        cnt[i]%=mod;
    }
    scanf("%d",&n);
    for(int i=0;i<n;i++)
       scanf("%lld",&a[i]);
    sort(a,a+n);
    for(int i=1;i<n;i++)
    {
        sum+=1LL*a[i]*(cnt[i]-1);//强制转化避免数据溢出;排序后从小到大每个数字有(p[i]-1)的机会成为子集中的最大值。
        sum%=mod;
    }
    for(int i=0;i<n-1;i++)//最后一个元素不可能为最小值,所以n-1
    {
        sum-=1LL*a[i]*(cnt[n-i-1]-1);//排序后从小到大每个数字有(p[n-i-1]-1)的机会成为子集中的最小值
        sum%=mod;
    }
    if(sum<0)//前面在取余求和的时候数据可能会炸掉,所以要加个mod再取余,或者是像这里写的一样取余以后再判断是否小于0
       {
           sum+=mod;
           sum%=mod;
       }
    printf("%lld\n",sum);
}
Android CCodec (十一) Codec2Buffer BufferPool分析 1、序言 2、C2BlockPool分析 3、SimpleC2Component关于BlockingBlockPool的实现 4、总结 阅读详情

相关推荐

医学图像处理实战:3D Slicer从安装到病灶分析全流程指南

本文提供了一份详尽的3D Slicer实战指南,涵盖从软件安装、DICOM数据导入到图像增强、病灶分割及三维可视化的全流程。重点演示了如何利用阈值分割、区域生长等核心图像处理技术进行病灶分析,并生成定量报告,是医学影像分析初学者的实用入门教程。

weixin_29278805的博客 622

Codeforces Round #279 (Div. 2) C. Hacking Cypher

没做出三个题。 掉分了。 坑

Shimmer_的专栏 794

字符集的选择

字符集的选择 一:背景介绍 DICOM特定字符集(0008,0005) 此标签获得不同的值就代表使用不同的语言进行解码。 以下为多家CT厂商的(0008,0005)取值: 字符集: unicode是字符集,ASCII、GB2312、GBK、GB18030既是字符集也是编码方式,UTF-8只是编码方式。 二:中文字符集介绍 世界通用字符集——UTF 中文字符集——GB2312、GBK、GB18030 字符集的详细介绍 一:UTF-8 程序是把一个字节一个字节的来读取,然后再根据字节中开头的bit

qq_41972968的博客 1527

Codeforces Round #415 (Div. 2)C. Do you want a date? (数学归纳)

C. Do you want a date? time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Leha decided to move to a quiet town Vičkopoli

HHH_go_的博客 1366

一文吃透 BMS:动力电池与储能共用的电池管控全架构详解

BMS作为电池系统的核心控制器,其技术深度和系统复杂性不容小觑。动力电池与储能系统虽然应用场景不同,但在核心架构上共享大量基础技术。成功的BMS设计需要在精度、可靠性、成本、功耗之间找到最佳平衡点。未来,随着电池技术的进步和智能化需求的提升,BMS将向着更高集成度、更强智能化、更优经济性的方向发展。无论是汽车工程师还是储能系统设计师,深入理解BMS的全栈架构,掌握其核心技术原理,都将是应对未来能源存储挑战的关键能力。核心要点回顾BMS采用分层分布式架构,硬件是基础,算法是灵魂。

小帽子的博客 354

国内开发者福音:手把手教你用微软Authenticator搞定GitHub 2FA验证(附Recovery Codes保存指南)

本文详细介绍了国内开发者如何使用微软Authenticator中国版轻松配置GitHub双重身份验证(2FA),解决短信验证不可用和国际验证器访问困难的问题。重点强调了恢复码(Recovery Codes)的安全备份策略,确保账户安全无忧。

weixin_28840143的博客 448

codeforces round #415 C.Do you want a Date?

题意:给n个坐标,你可以挑选任意组合,每个组合的距离为该组合的最大值-最小值,求所有组合的值的和 思路:按坐标从大到小排序后,从0~n-2往后取相邻两点,求这段距离用了多少次*该距离差值,求用的次数:每段距离左边和右边至少个选一个点,即(2的x(左边点的个数)次方-1)*2的y(右边点的个数)次方-1),用快速幂维护一个枚举数组(2的x(点的个数)次方)即可(刚开始忘了快速幂,真的菜) #in

exp1ore的博客 410

YOLOv8【第十章:多任务扩展深度篇·第16节】车道线检测——基于 YOLOv8-Seg 的车道线分割与拟合!

🏆 本文收录于 《YOLOv8实战:从入门到深度优化》 专栏。该专栏系统复现并梳理全网各类 YOLOv8 改进与实战案例(当前已覆盖分类 / 检测 / 分割 / 追踪 / 关键点 / OBB 检测等方向),坚持持续更新 + 深度解析,质量分长期稳定在 97 分以上,可视为当前市面上 覆盖较全、更新较快、实战导向极强 的 YOLO 改进系列内容之一。

**My Coding Family** 1万+

Codeforces Round #415 (Div. 2) C. Do you want a date? 数学

题目: C. Do you want a date? time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Leha decided to m

Na_OH的博客 490

图解联合概率密度、边缘概率密度、条件概率密度之间的关系

简要图解联合概率密度、边缘概率密度、条件概率密度之间的关系

一个搬运知识的笨小孩 2万+

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

Codeforces Round #415 (Div. 2) C. Do you want a date?

A. Do you want a date?

会打架的程序员不是好客服 277

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Codeforces Round #415 (Div. 2)-C. Do you want a date?

原题链接 C. Do you want a date? time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Leha decided to move to a

L. 634

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

Codeforces Round #415 (Div. 2) C. Do you want a date?

有一个集合S={1,2,3,4,5,6},他的一个子集的最大值是4,最小值是1,则这样的子集的个数是2^2,因为最大为4最小为1的集合最大是{1,2,3,4},1,4固定了,剩下的就是{2,3}的子集的个数了,{2,3}有2^2个子集,所以。。。。 假设一个集合,已经从小到大排序好了,则他的子集中最小为num[i],最大为num[j] (i < j) 的集合的个数为2^(j-i-1),即2^k(k

梦幻的蔷薇色 386

Codeforces Round #415 (Div. 2) C. Do you want a date? 【前缀和】

先把输入排个序,对于每个ai{a_i}和aj{a_j}来说,对最后的答案的贡献是 (aj−ai)∗2j−i−1{(a_j-a_i)*2^{j-i-1}} 。这样复杂度在 n2{n^2}。再化简一下式子,我们可以发现每个ai{a_i} 对于答案的贡献是 ai∗(fi−fn−i−1){a_i*(f_i-f_{n-i-1} )},其中fi=20+21+...2i{f_i=2^0+2^1+...2^i}。/

禅境花园 335

Codeforces Round #469 (Div. 2) D. A Leapfrog in the Array (思维)

题目大意:最开始n个数字中的数字i在位置2*i-1,之后从右向左依次用数字将该列填充。最后q个query问你pos为Xi该填上什么数字。 解析:首先n范围1e18,直接模拟肯定不行,但肯定有什么规律在里面,我们自己写写看n=6的时候,1~6位置分别为1 4 2 6 3 5,n=3的时候1~3位置分别为1 3 2,这里我们可以明显的发现,当Xi&amp;1时,该位置最后的数字就是Xi/2+1。...

喵喵喵? 1257

Codeforces Round #499 (Div. 1) C. Border || Codeforces Round #499 (Div. 2) E.Border(数论/贝祖定理)

                Codeforces Round #499 (Div. 1) C. Border                 Codeforces Round #499 (Div. 2) E. Border                                          (数论/贝祖定理)   题意:给你n个数字(十进制),每个数字都可以使用无限次...

喵喵喵? 992

ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals

Molly’s Chemicals time limit per test 2.5 seconds memory limit per test 512 megabytes Description Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has

喵喵喵? 903

Codeforces Round #476 (Div. 2) [Thanks, Telegram!] C. Greedy Arkady(brute force/math)

C. Greedy Arkady 传送门 这题的关键就是算出自己一共receive了多少次,我们可以很容易的便推出这么一个式子—&gt;(nx+k−1)k(nx+k−1)k\frac{(\frac{n}{x}+k-1)}{k} 之后嘛暴力二分一下就好啦 #include&lt;cstdio&gt; #include&lt;iomanip&gt; #include&lt;cstring&...

喵喵喵? 859

Codeforces Round #480 (Div. 2) D. Perfect Groups(数论/xjblg)

D. Perfect Groups 传送门 今天vp了一下昨天的这场比赛,结束后看着rank,还好没打, 这场完全就是题意场啊,做题10mins,读题1h…….. 这个D题题意是真的有点魔性: 首先第一段描述的ansansans是指给你一个array,使得你能将他分成numnumnum个集合,使得集合中任意两个书之积为完全平方数,且numnumnum是满足条件的最小集合数。 第二三...

喵喵喵? 789

Codeforces Round #478 (Div. 2) D. Ghosts(几何)

D. Ghosts 传送门 昨晚过掉前三题后看了眼D,噫….几何题,溜了溜了,准备明天(今天)的考试去了。 实际上这题只要思路对了操作起来其实很简单。 对于两个起始坐标分别为(Xi,aXi+b)和(Xj,aXj+b)(Xi,aXi+b)和(Xj,aXj+b)(Xi,aXi+b)和(Xj,aXj+b)的两个来说,他们两个在运动中碰撞当且仅当坐标相同,那么我们可以列出以下两条式子: Xi...

喵喵喵? 649

Codeforces Round #485 (Div. 1) C. AND Graph // Codeforces Round #485 (Div. 2) F. AND Graph

F. AND Graph 首先我们可以知道,对于一个数xxx,他与与他所有位取反的数进行&amp;amp;操作的结果肯定是0. 进一步做一个小推论,对于取反的得到的数我们叫他inverse简称invsinverse简称invsinverse简称invs,我们可以发现对这样一个有效的invsinvsinvs,我们任意将他某一位的1变成0得到的下一个数同样可以连到xxx上。 在得到以上的小推论之后,...

喵喵喵? 618

Codeforces Round #476 (Div. 2) [Thanks, Telegram!] D - Single-use Stones(思维)

D - Single-use Stones 传送门 题意:青蛙过河,有点暴力啊,苟. 解:其实很简单,我们这样想,青蛙的移动距离是[0,l][0,l][0,l],那么每次青蛙移动我们都可以看作是lll这么一段在移动(跳出lll外面的我们已经不用管他了),真正影响是否能到河对面的是这lll里是否有足够的落脚点,我们找到lll里最少的落脚点即是ansansans. #include&lt;...

喵喵喵? 605

Codeforces Round #415 B Summer sell-off

Summer sell-off time limit per test1 second memory limit per test256 megabytesDescription Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a

喵喵喵? 560

Codeforces Round #498 (Div. 3) F. Xor-Paths(折半搜索)

Codeforces Round #498 (Div. 3) F. Xor-Paths emmmm,多校的题目做傻了,昨晚看到这题就蒙蔽了,已经菜到连div3 F 都无法识破了...... 说白了这就折半搜索的裸题.   传送门 #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;algorithm&gt; #inc...

喵喵喵? 550

Codeforces Round #415 A Straight <<A>>

Straight << A >> time limit per test1 second memory limit per test256 megabytes Description Noora is a student of one famous high school. It’s her final year in school — she is going to study in uni

喵喵喵? 539
上一篇: Codeforces Round #415 B Summer sell-off
下一篇: UVa NO.10006 Carmichael Numbers
Murphyc
博客等级 码龄10年 13粉丝 86原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值