2868. 子串分值 - AcWing题库(python)
s=[0]+ list(input()) #6
n=len(s)
# 左边
l=[0]*n
# 右边
r=[0]*n
p=[0]*26# 枚举每个
for i in range (1,n):
t = ord(s[i])-ord("a")
l[i]=p[t]
p[t]=ifor i in range (26):
p[i]=n
for i in range (n-1,0,-1):
t=ord(s[i])-ord('a')
r[i]=p[t]
p[t]=i
res =0
for i in range (1,n):
res +=((i-l[i]) * (r[i]-i))
print(res)