Corner case of subarray

Considering a sub array case which starts from a[0][1] to a[2][3], a[li -1][bj] would be out of index, but can you explain some corner cases with this approach?

i don’t understand your question can you explain a bit more

li is for top-left x coordinate, bj is for bottom right y coordinate, in the case mentioned above you won’t be able to access a[0-1][3]

why we can’t access?
we can

you can access a[-1][3]?

but why you want to access a[-1][3]
this is out of range of array

it think i did not get your question please explain
what problem are you facing?

sum += pre[bi][bj] - pre[li-1][bj] - pre[bi][lj-1] + pre[li-1][lj-1];

This is the main formula derived in the tutorial, and at some point, li, lj, bi, bj == 0, so in that case accoding to formula we would go out of index

okay i got you

you are right
you have to check it first
here is complete code for this
for(int tli=0;tli<n;tli++){
for(int tlj=0;tlj<m;tlj++){
for(int bri=tli;bri<n;bri++){
for(int brj=tlj;brj<m;brj++){
/// now you have 4 cordinates
/// and you can find sum of these submatrix easly
int ans=sum[bri][brj];
if((tli-1>=0)&&(tlj-1>=0))ans+=sum[tli-1][tlj-1];
if(tli-1>=0)ans-=sum[tli-1][brj];
if(tlj-1>=0)ans-=sum[bri][tlj-1];
finalans+=ans;
}
}
}
}