提交时间:2022-10-15 11:24:13

运行 ID: 60304

#include <bits/stdc++.h> using namespace std; inline int read(){ int x=0,f=1;char ch=getchar(); for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=-1; for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch^48); return x*f; } const int mod=1e9+7; int n,a[500005],ans,sum[2005],now,maxa; map<int,int> t; bitset<2005> tim; int main(){ // freopen("J3.in","r",stdin); // freopen("J3.out","w",stdout); n=read(); for(int i=1;i<=n;i++) a[i]=read(); if(n<=2000){ if(maxa>2000){ for(int i=1;i<=n;i++) sum[i]=(sum[i-1]+a[i])%mod; for(int i=0;i<n;i++) for(int j=i+1;j<=n;j++) (ans+=sum[j]-sum[i]+mod)%=mod; } else{ for(int i=1;i<=n;i++){ tim.reset(); now=0; for(int j=i;j<=n;j++){ if(!tim[a[j]]) (now+=a[j])%=mod,tim[a[j]]=1; (ans+=now)%=mod; } } } printf("%d\n",ans); return 0; } for(int i=1;i<=n;i++) ans=(1ll*a[i]*i%mod*(n-i)%mod+ans)%mod; printf("%d\n",ans); return 0; }