您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: