Skip to content

Instantly share code, notes, and snippets.

@pikeas
Created October 9, 2011 16:50
Show Gist options
  • Save pikeas/1273904 to your computer and use it in GitHub Desktop.
Save pikeas/1273904 to your computer and use it in GitHub Desktop.
Recursive fail
class SegmentTree:
def __init__(self, N, quads):
def _init(b, e):
if b is e:
q = [0] * 4
q[quads[b]] = 1
return Node(b, e, q, None, None)
else:
mid = (b + e ) / 2
L = _init(b, mid)
R = _init(mid + 1, e)
q = [0] * 4
for i in xrange(4):
q[i] += L.quads[i]
q[i] += R.quads[i]
return Node(b, e, q, L, R)
self.root = _init(1, N)
quads = [0] * 301
tree = SegmentTree(300, quads)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment