提交时间:2022-10-15 11:27:18
运行 ID: 60348
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll maxn=500010,mod=1e9+7; ll a[maxn],n,ans,que[maxn]; bool Same; map<ll,ll>mp; int main() { // freopen("J3.in","r",stdin); // freopen("J3.out","w",stdout); scanf("%lld",&n); for(int i=1; i<=n; i++) scanf ("%lld",&a[i]); for(int i=1; i<=n; i++) que[i]=mp[a[i]],mp[a[i]]=i; ans=0; for(int i=1; i<=n; i++) (ans+=((i-que[i])*1ll*(n-i+1ll))%mod*a[i])%=mod; printf("%lld\n",ans); return 0; }