HDU 5496——Beauty of Sequence——————【考虑局部】
Beauty of Sequence
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 384 Accepted Submission(s): 168
Now you are given a sequence A of n integers {a1,a2,...,an}. You need find the summation of the beauty of all the sub-sequence of A. As the answer may be very large, print it modulo 109+7.
Note: In mathematics, a sub-sequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example {1,3,2} is a sub-sequence of {1,4,3,5,2,1}.
The first line contains an integer n (1≤n≤105), indicating the size of the sequence. The following line contains n integers a1,a2,...,an, denoting the sequence(1≤ai≤109).
The sum of values n for all the test cases does not exceed 2000000.

#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
const int mod=1e9+7;
const int maxn=1e5+200;
INT a[maxn];
INT pow2[maxn];
map<int,INT>coun;
int main(){
int T,n;
scanf("%d",&T);
pow2[0]=1;
for(int i=1;i<=maxn-100;i++){
pow2[i]=pow2[i-1]*2%mod;
}
while(T--){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%I64d",&a[i]);
}
coun.clear();
coun[0]=1;
INT ans=0;
for(int i=1;i<=n;i++){
INT pre=coun[a[i]];
INT tpre=pow2[i-1]-pre; //i-1
tpre=(tpre%mod+mod)%mod;
INT tmp=a[i]*tpre%mod*pow2[n-i]%mod;
ans=(ans+tmp)%mod;
pre=pow2[i-1]+pre;
coun[a[i]]=pre;
}
printf("%I64d\n",ans);
}
return 0;
}
HDU 5496——Beauty of Sequence——————【考虑局部】的更多相关文章
- Hdu 5496 Beauty of Sequence (组合数)
题目链接: Hdu 5496 Beauty of Sequence 题目描述: 一个整数序列,除去连续的相同数字(保留一个)后,序列的和成为完美序列和.问:一个整数序列的所有子序列的完美序列和? 解题 ...
- HDU 5496 Beauty of Sequence
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5496 Beauty of Sequence Problem Description Sequence ...
- HDU 5783 Divide the Sequence(数列划分)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- hdu-5496 Beauty of Sequence(递推)
题目链接: Beauty of Sequence Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java ...
- 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence
// 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...
- hdu 4893 Wow! Such Sequence!(线段树)
题目链接:hdu 4983 Wow! Such Sequence! 题目大意:就是三种操作 1 k d, 改动k的为值添加d 2 l r, 查询l到r的区间和 3 l r. 间l到r区间上的所以数变成 ...
- Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)
Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...
- HDU 5063 Operation the Sequence(暴力)
HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...
- HDU 5288 OO’s Sequence [数学]
HDU 5288 OO’s Sequence http://acm.hdu.edu.cn/showproblem.php?pid=5288 OO has got a array A of size ...
随机推荐
- kubeadm 搭建 K8S集群
kubeadm是K8s官方推荐的快速搭建K8s集群的方法. 环境: Ubuntu 16.04 1 安装docker Install Docker from Ubuntu’s repositories: ...
- 问题:C#调webservice超时;结果:C#调用webservice服务超时
C#调用WebService服务时,报错,The operation has timed out,意思是“操作超时”. 方法/步骤 首先修改服务端配置 WebService服务所在站点为服务端,它提供 ...
- shell分库备份
分库备份企业实战题7:如何实现对MySQL数据库进行分库备份,请用脚本实现 #!/bin/bash MysqlUser=root PassWord=root Port= Socket="/u ...
- Intent的简单概述
Intent是负责在系统组件之间传递信息的一个对象,就像名字一样,是一个意图,可以将当前组件的意图传递给系统,例如启动Activity等,还可以在传递的时候附加上一些值,可以用Bundle对象封装这些 ...
- 使用SecureCRT工具部署项目
总结下我的Java开发过程的一些知识点: 我要上线某个项目,此时我需要给测试人员发送安全扫描文件,等待测试人员完成项目的扫描之后才可以完成上线: 1 将项目打成war包.比如implgtyy.war文 ...
- hadoop-maven项目打包成可执行的jar
环境: cdh5.1.0 jdk1.7 <build> <plugins> <!--指定JDK为1.7 --> <plugin> <groupId ...
- unreal3对象管理模块分析
凡是稍微大一点的引擎框架,必然都要自己搞一套对象管理机制,如mfc.qt.glib等等,unreal自然也不例外. 究其原因,还是c++这种静态语言天生的不足,缺乏运行时类型操作功能,对于复杂庞大的逻 ...
- Vue packages version mismatch: 版本冲突;Error: EPERM: operation not permitted
1.npm install vue-template-compiler@2.5.3 出现此问题 npm ERR! path G:\XXX.Web\node_modules\fsevents\node_ ...
- 【转】webservice
一.WebService概念 Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它 ...
- VR中运动控制器的传送系统
创建一个VRPawn 新建一个BluePrint,父类选择Pawn,我们命名为VRPawn,打开它. 添加一个Scene命名为CameraRoot 在CameraRoot节点下添加一个Camera 在 ...