# 11265: 【原1265】raising pigs

### 题目描述

author: 王立力 原OJ链接：https://acm.sjtu.edu.cn/OnlineJudge-old/problem/1265

1.买若干只猪养在某个猪圈格子里

2.数一数一个矩形里有多少只猪

## Input Format

1. c=1,后面有3个整数x,y,a,表示在x,y位置增加了a只猪

2. c=2,后面有4个整数 x1,y1,x2,y2，表示查询矩形(x1,y1,x2,y2)里猪的数量

3. 表示结束

n<=2000,0<=x,y,x1,y1,x2,y2<=n-1

a<=2000

## Sample Input

3 2 0 0 2 2 1 1 1 1 2 0 0 2 2 1 1 1 2 2 0 0 2 2 3

0 1 3

## yyong119's solution

``````#include <iostream>
#include <cstdio>
#define MAX_N 2050
using namespace std;
int n, op;
int tree[MAX_N][MAX_N];
char ch = getchar(); int flag = 1, res = 0;
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') flag = -1, ch = getchar();
while (ch >= '0' && ch <= '9') res = res * 10 + ch - '0', ch = getchar();
return res;
}
void add(int x, int y, int num) {
for (; x <= n; x += x & -x)
for (int tmp_y = y; tmp_y <= n; tmp_y += tmp_y & -tmp_y)
tree[x][tmp_y] += num;
}
int query(int x, int y) {
int res = 0;
for (; x; x -= x & -x)
for (int tmp_y = y; tmp_y; tmp_y -= tmp_y & -tmp_y)
res += tree[x][tmp_y];
return res;
}
int main() {
while(op != 3) {
if (op == 1) {