vijos 1512 SuperBrother打鼹鼠
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1050;
int c[maxn][maxn], n;
inline int lowbit(int x) {
return x & (-x);
}
void add(int x, int y, int k) {
while (y <= n) {
c[x][y] += k;
y += lowbit(y);
}
}
int sum(int x, int y) {
int t = 0;
while(y > 0) {
t += c[x][y];
y -= lowbit(y);
}
return t;
}
int main()
{
cin >> n;
while(1) {
int m;
cin >> m;
if(m == 1) {
int x, y, k;
cin >> x >> y >> k;
add(x + 1, y + 1, k);
}
if(m == 2) {
int x1, y1, x2, y2, ans = 0;
cin >> x1 >> y1 >> x2 >> y2;
for (int i = x1 + 1; i <= x2 + 1; i ++) {
ans += sum(i, y2 + 1) - sum(i, y1);
}
cout << ans << endl;
}
if(m == 3) {
break;
}
}
return 0;
}