提交时间:2022-10-15 11:25:33

运行 ID: 60323

#include<bits/stdc++.h> using namespace std; const int P=1e9+7,N=5e5+10; int n,a[N],lst[N]; int ans; map<int,int> mp; int main(){ //freopen("J3.in","r",stdin); //freopen("J3.out","w",stdout); scanf("%d",&n); for(register int i=1;i<=n;i++){ scanf("%d",&a[i]); lst[i]=mp[a[i]]; mp[a[i]]=i; } for(register int i=1;i<=n;i++){ int bt=i-lst[i]; ans=(ans+(long long)bt*(n-i+1)%P*(long long)a[i]%P)%P; } printf("%d",ans); return 0; }