提交时间:2022-10-15 11:23:52

运行 ID: 60300

#include<bits/stdc++.h> using namespace std; int n,a[500005],pos[500005]; long long ans=0; map<int,int>vis; int main(){ cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; for(int i=1;i<=n;i++)pos[i]=vis[a[i]],vis[a[i]]=i; for(int i=1;i<=n;i++)ans=(ans+((i-pos[i])*1ll*(n-i+1)%1000000007*1ll*a[i]%1000000007))%1000000007; return cout<<ans<<'\n',0; }