I followed the exact same method. But getting "wrong answer on SPOJ. Although, the example input / output is matching when manually entered on other IDEs. My code is https://ide.codingblocks.com/s/205936
Getting wrong answer on SPOJ
sorry, its working. forgot to reset the value of BIT array after each test case