二维线段树模板
来源:互联网 发布:淘宝助理6.0官方下载 编辑:程序博客网 时间:2024/06/06 09:42
void update_x(int rooty, int rootx, int L, int R, int x, int a) //tree[rooty][rootx]对应的矩阵x方向上范围是[L,R]{ tree[rooty][rootx] += a; if( L == R ) return; int mid = (L + R )/2; if( x <= mid ) update_x(rooty,( rootx << 1) + 1, L ,mid, x, a);else update_x(rooty,( rootx << 1) + 2, mid + 1,R, x, a);}void update_y(int rooty, int L, int R, int y, int x, int a) //tree[rooty][rootx]对应的矩阵y方向上范围是[L,R] { update_x( rooty,0, 1, S, x,a); if( L == R) return; int mid = (L + R )/2;if( y <= mid ) update_y( ( rooty << 1) + 1, L, mid,y, x, a); elseupdate_y( ( rooty << 1) + 2, mid+1, R, y, x, a); }int query_x(int rooty, int rootx, int L, int R, int x1, int x2) { if (L == x1 && R == x2)return tree[rooty][rootx]; int mid = (L + R) / 2; if (x2 <= mid)return query_x(rooty, (rootx << 1) + 1, L, mid, x1, x2); else if (x1 > mid)return query_x(rooty, (rootx << 1) + 2, mid + 1, R, x1, x2); elsereturn query_x(rooty, (rootx << 1) + 1, L, mid, x1, mid) + query_x(rooty, (rootx << 1) + 2, mid + 1, R, mid + 1, x2); }int query_y(int rooty, int L, int R, int y1, int y2, int x1, int x2){if (L == y1 && R == y2)return query_x(rooty, 0, 1, S, x1, x2);int mid = (L + R) / 2;if (y2 <= mid)return query_y((rooty << 1) + 1, L,mid, y1, y2, x1, x2);if (y1 > mid)return query_y((rooty << 1) + 2,mid + 1, R, y1, y2, x1, x2);elsereturn query_y((rooty << 1) + 1, L,mid, y1, mid, x1, x2) +query_y((rooty << 1) + 2,mid + 1, R, mid + 1, y2, x1, x2);}
0 0
- 二维线段树模板
- 二维线段树模板
- 二维线段树 模板题
- 【HDU 4819】Mosaic 二维线段树模板
- HDU 4819 Mosaic(二维线段树模板)
- 二维线段树模板题 hdu 4819
- 二维线段树(模板)+HDU 4819
- UVa 11297 Census 二维线段树模板
- HDU1823-Luck and Love-二维线段树(模板)
- POJ 2155 Matrix 【二维线段树模板题】
- HDU 1823 Luck and Love (二维线段树模板)
- poj 1195 二维线段树(模板题)
- hihocoder #1336 : Matrix Sum 二维线段树 或 二维树状数组模板
- 二维线段树
- poj1656----二维线段树
- poj2155 二维线段树
- hdu1823 二维线段树
- POJ2155 二维线段树
- Java数据结构学习1--List
- c内存系列(一):缓冲区溢出
- 码农小汪-Hibernate学习10-hibernate继承映射 @DiscriminatorColumn DiscriminatorType @Inheritance InheritanceType
- bzoj 1098
- 设计模式
- 二维线段树模板
- frame、bounds、center
- 上传资源下载
- bzoj 3223
- HTML5学习第一天
- 网络编程初尝
- JAVAEE学习查询
- JFinal的getModel实现方式
- 4Sum