记录编号 166606 评测结果 AAAAAAAAAA
题目名称 [IOI 2001] 移动电话 最终得分 100
用户昵称 Gravatar啊吧啦吧啦吧 是否通过 通过
代码语言 C++ 运行时间 0.482 s
提交时间 2015-06-15 19:56:24 内存使用 4.32 MiB
显示代码纯文本
#include <fstream>

using namespace std;

const int MAXS = 1025;
int f[MAXS][MAXS] = {0}, zl, s, x, y, x1, y1, a, b, l, r, t;
inline int sum(int, int), lowbit(int);
inline void modify(int, int, int);
ifstream fi("mobilephones.in");
ofstream fo("mobilephones.out");
#define cin fi
#define cout fo

main()
{
//	ios::sync_with_stdio(0);
	cin >> zl;
	if(zl == 0)
		cin >> s;
	cin >> zl;
	while(zl!=3)
	{
		if(zl==1)
		{
			cin >> x >> y >> a;
			modify(++ x, ++ y, a);
		}
		else if(zl == 2)
		{
			cin >> l >> b >> r >> t;
			cout<<sum(++r,++t)-sum(++l-1,t)-sum(r,++b-1)+sum(l-1,b-1)<<endl;
		}
		cin >> zl;
	}
}

inline int lowbit(int x)
{
	return x & (-x);
}

inline void modify(int x, int y, int z)
{
	for(int i = x; i <= s; i += lowbit(i))
		for(int j = y; j <= s; j += lowbit(j))
			f[i][j] += z;
}

inline int sum(int x,int y)
{
	int tot = 0;
	for(int i = x; i > 0; i -= lowbit(i))
		for(int j = y; j > 0; j -= lowbit(j))
			tot += f[i][j];
	return tot;
}