比赛 EYOI暨SBOI暑假快乐赛3rd 评测结果 AAAAAAAAAA
题目名称 移动电话 最终得分 100
用户昵称 Lfc_HeSn 运行时间 0.924 s
代码语言 C++ 内存使用 6.96 MiB
提交时间 2022-06-27 09:13:55
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int n, c[1050][1050] = {0};
int lowbit(int x) {
	return x & -x;
}
int add(int x, int y, int a) {
	for(int i = y; i <= n; i += lowbit(i)) {
		c[x][i] += a;
	}
	return 0;
}
int sum(int x, int y) {
	int ans = 0;
	for(int i = y; i >= 1; i -= lowbit(i)) {
		ans += c[x][i];
	}
	return ans;
}
int main() {
    freopen("mobilephones.in", "r", stdin);
    freopen("mobilephones.out", "w", stdout);
    int xx;
    cin >> xx >> n;
	while(cin >> xx && xx != 3) {
		if(xx == 1) {
			int x, y, z;
			cin >> x >> y >> z;
			add(x + 1, y + 1, z);
		}
		if(xx == 2) {
			int a, b, c, d, ans = 0;
			cin >> a >> b >> c >> d;
			for(int i = a + 1; i <= c + 1; i ++) {
				ans = ans + sum(i, d + 1) - sum(i, b);
			}
			cout << ans << endl;
		}
	}
    return 0;
}