Iterative Segtree for Xenia and Bit Operations (CF)

I am trying to solve https://codeforces.com/problemset/problem/339/D 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