#include<stdio.h>
#include<string.h>
#include<stack>
#include<string>
#include<math.h>
#include<queue>
#include<set>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
using namespace std;
#define LL long long
#define inf 199999999
#define N 100010
#define mod 1000000007
LL mul(int n)
{
LL res=1,x=2;
while(n)
{
if(n&1)
res=(res*x)%mod;
x=(x*x)%mod;
n>>=1;
}
return res;
}
map<LL,int>pos;
int a[N];//位置i的这个数计算过的次数
int main()
{
int i,j,n,m,t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
pos.clear();
LL res=0;
LL x;
for(i=1;i<=n;i++)
{
scanf("%lld",&x);
if(!pos.count(x))//如果没有出现过,x要计算2^(n-1)次
{
a[i]=0;
res=(res+x*mul(n-1))%mod;
}
else//如果出现过,有重复的,x要被计算前面2^(i-1)-上次出现计算的次数,即a[x上次]
{ //和后面2^(n-i)次
a[i]=a[pos[x]];
res=(res+x*(mul(i-1)-a[i])%mod*mul(n-i))%mod;
}
pos[x]=i;
a[i]=(a[i]+mul(i-1))%mod;//更新a,当前这个数出现了2^(i-1)以前的这个数出现了a[i];
}
printf("%lld\n",(res+mod)%mod);
}
return 0;
}
hdu 5496 Beauty of Sequence
最新推荐文章于 2015-10-24 20:36:00 发布