class BinaryIndexedTree:
def __init__(self, n):
self.n = n
self.c = [0] * (n + 1)
def update(self, x, val):
while x <= self.n:
self.c[x] = max(self.c[x], val)
x += x & -x
def query(self, x):
s = 0
while x:
s = max(s, self.c[x])
#x -= x & -x
x &= (x - 1)
return s
python树状数组模板
最新推荐文章于 2024-04-30 21:03:59 发布