Meaning of the title: the number to $ n $,
(Section length * number of different numbers in the interval) defined Beauty Values for all its successive summing subinterval
求Beauty Values
A [i] i represents a number array appears last when, increasing a number i, A [i] due to just before the change in length of the section, there is no increase in the digital type,
DP [i] records ans i between i-1 and the difference
#include<bits/stdc++.h> using namespace std; int A[100004]; //int B[100004]; typedef long long ll; ll dp[100004]; ll ans=0,t=0; int n; int main() { scanf("%d",&n); int x; for(int i=1;i<=n;i++){ scanf("%d",&x); if(A[x]==0){ ans+=(dp[i-1]+i); dp[i]=ans-t; A[x]=i; t=ans; }else{ ans+=dp[i-1]+i-A[x]; dp[i]=ans-t; A[x]=i; t=ans; } } cout<<ans<<'\n'; }