三个月算法进阶--day77
目录
python bisect
有序序列的查找与插入,bisect.bisect/bisect.bisect_left/bisect.insort/bisect.insort_left
序列的离散化
当序列的值域很大,算法复杂度又是O(n)的,同时只用关心元素的相对大小,不关心绝对大小
树状数组
动态维护序列前缀和的数据结构,单点更新和前缀和查询的时间代价为O(log n)
class BIT:
def __init__(self, n):
self.n = n
self.tree = [0] * (n + 1)
@staticmethod
def lowbit(x):
return x & (-x)
def query(self, x):
ret = 0
while x > 0:
ret += self.tree[x]
x -= BIT.lowbit(x)
return ret
def update(self, x):
while x <= self.n:
self.tree[x] += 1
x += BIT.lowbit(x)
|
树状数组、线段树、trie树、红黑树、并查集
记录
leetcode剑指offer第51题数组中的逆序对
归并排序
|