poj 1195 Mobile phones
2014-02-11 16:24
330 查看
http://poj.org/problem?id=1195
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 1026
using namespace std;
int a[maxn][maxn];
int c[maxn][maxn];
int S,x,y,aa,l,r,b,t,h,T;
int lowbit(int x)
{
return x&(x^(x-1));
}
void update(int i,int j,int k)
{
while(i<=S)
{
int temp=j;
while(temp<=S)
{
c[i][temp]+=k;
temp+=lowbit(temp);
}
i+=lowbit(i);
}
}
int sum(int i,int j)
{
int sum1=0;
while(i>0)
{
int temp=j;
while(temp>0)
{
sum1+=c[i][temp];
temp-=lowbit(temp);
}
i-=lowbit(i);
}
return sum1;
}
int main()
{
while(scanf("%d",&h))
{
if(h==0)
{
scanf("%d",&S);
memset(c,0,sizeof(c));
}
else if(h==3) break;
else if(h==1)
{
scanf("%d%d%d",&x,&y,&aa);
update(x+1,y+1,aa);
}
else if(h==2)
{
scanf("%d%d%d%d",&l,&r,&b,&t);
int sum1=sum(b+1,t+1);
int sum2=sum(l,t+1);
int sum3=sum(b+1,r);
int sum4=sum(l,r);
printf("%d\n",sum1-sum2-sum3+sum4);
}
}
return 0;
}
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 1026
using namespace std;
int a[maxn][maxn];
int c[maxn][maxn];
int S,x,y,aa,l,r,b,t,h,T;
int lowbit(int x)
{
return x&(x^(x-1));
}
void update(int i,int j,int k)
{
while(i<=S)
{
int temp=j;
while(temp<=S)
{
c[i][temp]+=k;
temp+=lowbit(temp);
}
i+=lowbit(i);
}
}
int sum(int i,int j)
{
int sum1=0;
while(i>0)
{
int temp=j;
while(temp>0)
{
sum1+=c[i][temp];
temp-=lowbit(temp);
}
i-=lowbit(i);
}
return sum1;
}
int main()
{
while(scanf("%d",&h))
{
if(h==0)
{
scanf("%d",&S);
memset(c,0,sizeof(c));
}
else if(h==3) break;
else if(h==1)
{
scanf("%d%d%d",&x,&y,&aa);
update(x+1,y+1,aa);
}
else if(h==2)
{
scanf("%d%d%d%d",&l,&r,&b,&t);
int sum1=sum(b+1,t+1);
int sum2=sum(l,t+1);
int sum3=sum(b+1,r);
int sum4=sum(l,r);
printf("%d\n",sum1-sum2-sum3+sum4);
}
}
return 0;
}
相关文章推荐
- 【poj 1195】Mobile phones 二维树状数组
- POJ1195 Mobile phones —— 二维树状数组(二维BIT)
- POJ1195 - Mobile phones
- poj 1195 Mobile phones
- POJ 1195 Mobile phones
- POJ 1195 - Mobile phones 二维树状数组(单点更新..区间查询)
- poj 1195 Mobile phones
- 【poj 1195】Mobile phones 题意&题解&代码(C++)
- POJ 1195 Mobile phones
- poj 1195 Mobile phones
- POJ 1195--Mobile phones (二维树状数组)
- poj 1195Mobile phones
- POJ 1195 Mobile phones
- poj 1195 Mobile phones
- poj 1195 Mobile phones
- 【二维树状数组--模板】poj 2155 Matrix、poj 1195 Mobile phones
- POJ1195 Mobile phones 二维数状数组
- poj 1195 Mobile phones (二维树状数组)
- POJ 1195 Mobile Phones
- POJ 1195 Mobile phones 题解