提交时间:2022-10-15 11:26:01

运行 ID: 60334

#include<bits/stdc++.h> using namespace std; typedef long long ll; const int Maxn=5e5+5; const int Mod=1e9+7; ll n,a[Maxn],lst[Maxn],ans; map<ll,int> m; inline ll read() { ll x=0,f=0; char c=getchar(); for(;c<'0' || c>'9';f^=(c=='-'),c=getchar()); for(;'0'<=c && c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48); return f?-x:x; } signed main() { //freopen("J3.in","r",stdin); //freopen("J3.out","w",stdout); n=read(); for(int i=1;i<=n;i++) { a[i]=read(); lst[i]=m[a[i]]; m[a[i]]=i; } for(int i=1;i<=n;i++) ans=(ans+1ll*a[i]*(i-lst[i])*(n-i+1)%Mod)%Mod; printf("%d\n",ans); return 0; }