title: Count Subarrays Total Distinct Elements Original Array
signature: def countSubarraysTotalDistinctElementsOriginalArray(arr: List[Int], n: Int) = {
source_py: def count_subarrays_total_distinct_elements_original_array(arr, n):
      vis = dict()
      for i in range(n):
          vis[arr[i]] = 1
      k = len(vis)
      vid = dict()
      ans = 0
      right = 0
      window = 0
      for left in range(n):
          while ((right < n) and (window < k)):
              if (arr[right] in vid.keys()):
                  vid[arr[right]] += 1
              else:
                  vid[arr[right]] = 1
              if (vid[arr[right]] == 1):
                  window += 1
              right += 1
          if (window == k):
              ans += ((n - right) + 1)
          vid[arr[left]] -= 1
          if (vid[arr[left]] == 0):
              window -= 1
      return ans
source_cpp: int count_subarrays_total_distinct_elements_original_array(vector<int> arr, int n) {
    unordered_map < int, int > vis;
    for ( int i = 0;
    i < n;
    ++ i ) vis [ arr [ i ] ] = 1;
    int k = vis . size ( );
    vis . clear ( );
    int ans = 0, right = 0, window = 0;
    for ( int left = 0;
    left < n;
    ++ left ) {
      while ( right < n && window < k ) {
        ++ vis [ arr [ right ] ];
        if ( vis [ arr [ right ] ] == 1 ) ++ window;
        ++ right;
      }
      if ( window == k ) ans += ( n - right + 1 );
      -- vis [ arr [ left ] ];
      if ( vis [ arr [ left ] ] == 0 ) -- window;
    }
    return ans;
  }