fork download
  1. #include <cstdio>
  2. #include <cmath>
  3. #include <map>
  4. #include <cstring>
  5. #include <algorithm>
  6. using namespace std;
  7. #define mst(a,b) memset((a),(b),sizeof(a))
  8. #define rush() int T;scanf("%d",&T);while(T--)
  9. typedef long long ll;
  10. const int maxn = 1000005;
  11. const ll mod = 1e9+7;
  12. const int INF = 0x3f3f3f3f;
  13. const double eps = 1e-6;
  14. int a[maxn],pre[maxn];
  15. int main()
  16. {
  17. int n,x;
  18. while(~scanf("%d",&n))
  19. {
  20. mst(pre,0);
  21. ll ans=0;
  22. ll temp=0;
  23. for(int i=1;i<=n;i++)
  24. {
  25. scanf("%d",&x);
  26. temp+=i-pre[x];
  27. pre[x]=i;
  28. ans+=(ll)temp*2-1;
  29. }
  30. printf("%.6f\n",ans*1.0/n/n);
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0s 4296KB
stdin
Standard input is empty
stdout
Standard output is empty