Count unique characters of all substrings
Instead of checking every substring, ask how many substrings each character is the only copy of its letter in. Its previous and next copies (found with a HashMap) bound that range, and the count is a simple product.
The window on s is where s[i] is the only copy of its letter. lastSeen maps each letter to its nearest index so far. left[i] is the previous copy of the letter (-1 if none), right[i] the next copy (n if none).