I can even advise to think about some binary packed structure, which may be really faster than tree. you can store sorted ranges of your ifs in one binary and make log2 access