提交时间:2022-10-15 11:28:29
运行 ID: 60366
#include<bits/stdc++.h> using namespace std; const int mod=1e9+7; map<int,int> wjj; long long n,a[500005],lst[500005]; long long ans; int main(){ // freopen("J3.in","r",stdin); // freopen("J3.out","w",stdout); scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); lst[i]=wjj[a[i]]; wjj[a[i]]=i; } for(int i=1;i<=n;i++){ ans+=(a[i]*(i-lst[i])%mod)*(n-i+1)%mod; ans%=mod; } printf("%lld\n",ans); return 0; }