提交时间:2022-10-15 11:32:40

运行 ID: 60427

#include<bits/stdc++.h> #define N 500001 using namespace std; const int mod = 1e9+7; long long ans; long long n, a[N]; long long sum[N], lst[N], pos[N]; bool vis[100000001]; int main() { cin.tie(0), cout.tie(0); cin >> n; for(int i=1;i<=n;i++) { cin >> a[i]; if(!vis[a[i]]) { lst[i] = pos[a[i]]; pos[a[i]] = i; sum[i]=sum[i-1]+a[i]; } if(vis[a[i]]) { pos[a[i]] = i; sum[i]=sum[i-1]; } vis[a[i]]=1; } memset(vis, 0, sizeof(vis)); for(int j=1;j<=n;j++) { for(int i=j;i<=n;i++) { if(!vis[a[i]]) { sum[i] = sum[i-1] + a[i]; vis[a[i]] = 1; } else sum[i] = sum[i-1]; ans = (ans + sum[i]) % mod; } memset(vis, 0, sizeof(vis)); memset(sum, 0, sizeof(sum)); } cout << ans % mod << endl; return 0; }