Created
October 9, 2011 16:50
-
-
Save pikeas/1273904 to your computer and use it in GitHub Desktop.
Recursive fail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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