Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official. ×

### ak3899's blog

By ak3899, history, 5 months ago, ,

i am trying to solve this spoj question Your text to link here... after looking at the problem someone can easily understand it's direct 2D-Binary Index Tree it's been more than 2 days but somehow i am missing something pls help me!! my soluiont is

Your code here...


# include <bits/stdc++.h>

using namespace std;

# define SZ 10000

int bit[SZ][SZ]; int data[SZ][SZ]; int R, C;

void update(int r, int c, int val) { int i,j; for (i = r; i <= R; i += i & -i) for (j = c; j <= C; j += j & -j) bit[i][j] += val; }

int sum(int r, int c) { int i,j,s = 0; for (i = r; i > 0; i &= i — 1) for (j = c; j > 0; j &= j — 1) s += bit[i][j]; return s; }

int main() {

int t,cs=1;
int n,m,q;
scanf("%d%d%d",&n,&m,&q);
// n--;m--;
R = n;
C = m;

ms0(bit);

for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>data[i][j];

}
}

while(q--)
{
int a,b,c,d,x1,x2,y1,y2;
cin>>a;
if(a==1)
{
cin>>b>>c>>d;
b++;c++;
update(b, c, d) ;
data[b][c]=d;
}
else if(a==2)
{
int x1,y1,x2,y2;
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
x1++,y1++,x2++,y2++;
int res =0;

res+=sum(x2, y2);
res-=sum(x1 - 1, y2);
res-=sum(x2, y1 - 1);
res+=sum(x1 - 1, y1 - 1);

printf("%d\n",res);
}
}
return 0;


}

•
• -3
•