双闭专题

leetcode 2916. 子数组不同元素数目的平方和 II(区间更新 + 区间查询 线段树第二个板子 双闭区间 避开0)

描述 偷了一个线段树板子 不知道为啥要避开0 然后这里的更新和查找都是用双闭区间的 ac code class SegmentTree:def __init__(self, n):self.n = n self.B1 = [0]*n self.B2 = [0]*n def add(self, b, idx, x):N = self.n while idx < N:b[idx] += xi