Why my code is giving WAs? Topic: SPOJ--MATSUM (2D BIT)

This problem requires concept of 2D BIT
Problem Link:SPOJ.com - Problem MATSUM
Code Link: Online Compiler and IDE - GeeksforGeeks

My Output:
0
12
0
12

Expected Output:
1
12
12
13

y loop is iterating just once.

1 Like

I Dont see any problem in that ,can you please elaborate ??

for (; y <= c; y += (y & -y)) 
            BIT[x][y] += val; 

this loop will process only once for first value of x.
when x=1,y=1,r=4,c=4
it will take only (1,1),(1,2),(1,4) whereas it should also take (2,1),(2,2),(2,4)…
fix y again with the parameter y. the sol will pass.

1 Like