classSolution:defdistinctDifferenceArray(self, a: List[int])-> List[int]:
ans =[]
n =len(a)for i inrange(n):
ans.append(len(set(a[:i +1]))-len(set(a[i +1:])))return ans
classSolution:defcolorTheArray(self, n:int, queries: List[List[int]])-> List[int]:
a =[0]*(n+2)
ans =[0]for i,c in queries:
i +=1
x = ans[-1]if a[i]== c:
ans.append(x)continueif a[i]== a[i-1]!=0:
x -=1if a[i]== a[i+1]!=0:
x -=1if c == a[i-1]:
x +=1if c == a[i+1]:
x +=1
ans.append(x)
a[i]= c
return ans[1:]
classSolution:defminIncrements(self, n:int, cost: List[int])->int:
ans =0defdfs(u):if u>n:return0nonlocal ans
l = dfs(u*2)
r = dfs(u*2+1)if l > r:
l,r= r,l
ans += r - l
return r + cost[u-1]
dfs(1)return ans