How to merge two nodes to form new number? HACKERBLOCKS - QUERY BITS

Continuing the discussion from Query Bits hackerblocks:

https://hack.codingblocks.com/contests/c/547/725

https://ide.codingblocks.com/s/74204 (TLE)

my approach: this.ans=(left.ans)*(2^(right.size))+right.ans, getting tle with this one due to 2^n%MOD operation in loop.

Hi

check this code