#https://www.hackerearth.com/notes/binary-indexed-tree-made-easy-2/ #from bottom to root follow a left path is to flip all the bits between the first right most 1 to #the first 0 right-after the 1 def sumRectangle(x, y): # sum every horizontal ones in every row sumt = 0 xt = x+1 while xt > 0: # sum every row yt = yt + 1 while yt > 0: sumt += self.BIT[xt][yt] yt -= yt & (-yt) # go to next row xt -= xt & (-xt)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question