本文主要是介绍poj1195(二维树状数组,点修改,区间求和),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:点击打开链接
//题目大意:一个平面区间,修改某个点的 number of active phones,区间求和#include <iostream>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define n 1500using namespace std;int c[1500][1500];void add(int x, int y, int d)
{for(int i= x; i<= n; i+= i&-i)for(int j= y; j<= n; j+= j&-j)c[i][j]+= d;
}int sum(int x, int y)
{int s= 0;for(int i= x; i> 0; i-= i&-i)for(int j= y; j> 0; j-= j&-j)s+= c[i][j];return s;
}int main()
{int instruction, s;while(scanf("%d", &instruction)== 1){if(instruction== 0){scanf("%d", &s);memset(c, 0, sizeof(c));while(scanf("%d", &instruction)== 1 && instruction!= 3){if(instruction== 1){int x, y, a; scanf("%d%d%d", &x, &y, &a); x++; y++;add(x, y, a);}if(instruction== 2){int k, l, m, p; scanf("%d%d%d%d", &k, &l, &m, &p); k++; l++; m++; p++;printf("%d\n", sum(m, p)- sum(m, l- 1)- sum(k- 1, p)+ sum(k- 1, l- 1));}}}}return 0;
}
这篇关于poj1195(二维树状数组,点修改,区间求和)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!