Hi, I'm a FiveAtomTree (5-indexed...), and I'm wondering how I can 0-index a BIT easily. I know I can just update upd(index+1, value), but at times it's really inconvenient.
I remember there was a comment on a contest announcement about it, but I forgot it and can't find it...
Anyone wanna hit me up?
Thanks~!
orz
http://ideone.com/8k2jMb
Thanks, can you please tell me how it works? Do you implement the normal BIT with i&( - i)? I can't see how i = (i&(i + 1)) - 1 works here.
Thanks!
It has the same structure of tree as with i&( - i), but all indices are shifted by 1, because of such function.
It's very easy to implement a 0-indexed BIT, all you need is to increase
pos
by 1 in the functionadd
andsum
.