Iterative Segtree for Xenia and Bit Operations (CF)

I am trying to solve Problem - 339D - Codeforces with an iterative segment tree. For some reason, my output for the first sample case only consists of 1s. Could someone please have a look at my code and tell me where I’m going wrong? Thanks!
https://pastebin.com/RPZSQJSj