Skip to content

Instantly share code, notes, and snippets.

Parth Mittal parthmittal

  • New Delhi, India
Block or report user

Report or block parthmittal

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
max_N = (1 << 20) #This is the maximum size of array our tree will support
seg = [0] * (4 * max_N) #Initialises the 'tree' to all zeroes.
def build(someList, v, L, R):
global seg
if (L == R):
seg[v] = someList[L]
mid = (L + R) / 2 #Integer division is equivalent to flooring.
build(someList, 2 * v, L, mid)
parthmittal /
Last active Jun 20, 2018
A class implementing the segment tree data structure
class segment_tree:
"""A class which implements a range sum tree"""
def __init__(self, some_list):
Initialises the tree, needs a list as a parameter
self.N = len(some_list)
self.seg = [0] * (4 * len(some_list))
You can’t perform that action at this time.