Links: https://ac.nowcoder.com/acm/contest/888/B
The meaning of problems: given a sequence, find all its subintervals Beauty (the number of kinds of section number). i <1e5, ai <1e5
Solution: Consider every kind of contribution to the answer, that is, considering the contribution of each number of the answer, look at this number appeared in the number of intervals.
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=1e5+5; int n, a[maxn], pre[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n; for(int i=1; i<=n; i++) cin>>a[i]; ll ans=0; for(int i=1; i<=n; i++) { ans+=1ll*(i-pre[a[i]])*(n-i+1); pre[a[i]]=i; } cout<<ans; return 0; }