提交时间:2024-01-02 13:35:06
运行 ID: 118910
#include<bits/stdc++.h> using namespace std; const int P=1e9+7,N=5e5+10; int n,a[N],lst[N],ans; map<int,int> mp; int main(){ 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; }