| 比赛 | 
    20110728 | 
    评测结果 | 
    AAAEEEEEEE | 
    | 题目名称 | 
    蝗灾 | 
    最终得分 | 
    30 | 
    | 用户昵称 | 
    .Xmz | 
    运行时间 | 
    0.000 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    0.00 MiB  | 
    | 提交时间 | 
    2011-07-28 10:17:14 | 
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#define low(x) ( x & (-x) )
using namespace std;
int x[2049][2049],n,m;
void add(int a,int b,int c)
{
	for (int i=a;i<=n;i+=low(i))
	for (int j=b;j<=n;j+=low(j))
	x[i][j]+=c;
}
int sum(int a,int b)
{
	int re=0;
	for (int i=a;i>0;i-=low(i))
	for (int j=b;j>0;j-=low(j))
	re+=x[i][j];
	return re;
}
int check(int a1,int b1,int a2,int b2)
{
	int t;
	t=max(a1,a2);a1=min(a1,a2);a2=t;
	t=max(b1,b2);b1=min(b1,b2);b2=t;
	return sum(a2,b2)-sum(a1-1,b2)-sum(a2,b1-1)+sum(a1-1,b1-1);
}
int main()
{
	freopen("locust.in","r",stdin);
	freopen("locust.out","w",stdout);
	scanf("%d%d",&n,&m);
	int a,b,c,d;
	for (;m;--m)
	{
		scanf("%d",&d);
		if (d==1)
		{
			scanf("%d%d%d",&a,&b,&c);
			add(a,b,c);
		}
		else
		{
			scanf("%d%d%d%d",&a,&b,&c,&d);
			printf("%d\n",check(a,b,c,d));
		}
	}
	return 0;
}