为每一个权值开一个二维树状数组.

-------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
 
#define rep(i, n) for(int i = 0; i < n; ++i)
#define Rep(i ,n) for(int i = 1; i <= n; ++i)
 
using namespace std;
 
const int maxn = 300 + 5;
 
#define lowbit(x) ((x) & -(x))
 
int n, m;
 
struct BIT {
int b[maxn][maxn];
BIT() { memset(b, 0, sizeof b); }
void add(int x, int y, int v) {
for(int i = x; i <= n; i += lowbit(i))
   for(int j = y; j <= m; j += lowbit(j))
       b[i][j] += v;
}
int sum(int x, int y) {
int ans = 0;
for(int i = x; i > 0; i -= lowbit(i))
   for(int j = y; j > 0; j -= lowbit(j))
       ans += b[i][j];
return ans;
}
};
 
const int maxc = 100 + 5;
 
BIT g[maxc];
int M[maxn][maxn];
 
int main() {
freopen("test.in", "r", stdin);
cin >> n >> m;
Rep(i, n)
   Rep(j, m) {
    scanf("%d", &M[i][j]);
    g[M[i][j]].add(i, j, 1);
   }
int q;
cin >> q;
while(q--) {
int op;
scanf("%d", &op);
if(op == 1) {
int x, y, v;
scanf("%d%d%d", &x, &y, &v);
g[M[x][y]].add(x, y, -1);
g[M[x][y] = v].add(x, y, 1);
} else {
int x1, x2, y1, y2, v;
scanf("%d%d%d%d%d", &x1, &x2, &y1, &y2, &v);
x1--; y1--;
printf("%d\n", g[v].sum(x2, y2) + g[v].sum(x1, y1) - g[v].sum(x1, y2) - g[v].sum(x2, y1));
}
}
return 0;
}

-------------------------------------------------------------------------

1452: [JSOI2009]Count

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 1384  Solved: 814
[Submit][Status][Discuss]

Description

Input

Output

Sample Input

Sample Output

1
2

HINT

Source

BZOJ 1452: [JSOI2009]Count(二维BIT)的更多相关文章

  1. BZOJ 1452: [JSOI2009]Count 二维树状数组

    1452: [JSOI2009]Count Description Input Output Sample Input Sample Output 1 2 HINT Source 题解:设定C[101 ...

  2. bzoj 1452: [JSOI2009]Count ——二维树状数组

    escription Input Output Sample Input Sample Output 1 2 HINT ———————————————————————————————————————— ...

  3. 二维树状数组 BZOJ 1452 [JSOI2009]Count

    题目链接 裸二维树状数组 #include <bits/stdc++.h> const int N = 305; struct BIT_2D { int c[105][N][N], n, ...

  4. bzoj 1452: [JSOI2009]Count (二维树状数组)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1452 思路: 对每个颜色开一个二维树状数组维护就好了 实现代码: #include<b ...

  5. bzoj1452 [JSOI2009]Count ——二维树状数组

    中文题面,给你一个矩阵,每一个格子有数字,有两种操作. 1. 把i行j列的值更改 2. 询问两个角坐标分别为(x1,y1) (x2,y2)的矩形内有几个值为z的点. 这一题的特点就是给出的z的数据范围 ...

  6. 【bzoj1452】[JSOI2009]Count 二维树状数组

    题目描述 输入 输出 样例输入 样例输出 1 2 题解 二维树状数组 一开始没看到 1≤c≤100 ,想到了主X树和X块,结果发现c的范围那么小... 二维树状数组水题,和一维的一样,向上修改,向下查 ...

  7. BZOJ 1452 [JSOI2009] Count

    这道题好像有点简单的样子... absi找题目好厉害啊...确实是一道比较裸的2dBIT啊. 水掉吧. 附:2dBIT怎么做: 2dBIT就是BIT套BIT啦. 所以修改loop(x+=lowbit( ...

  8. BZOJ 1452 Count(二维树状数组)

    大水题. 建立100个二维树状数组,总复杂度就是O(qlognlogm). # include <cstdio> # include <cstring> # include & ...

  9. 【BZOJ】1452: [JSOI2009]Count

    http://www.lydsy.com/JudgeOnline/problem.php?id=1452 题意:n×m的矩阵上每个点有个颜色,现在有q个操作:1 x y c 将点(x,y)的颜色改为c ...

随机推荐

  1. java把函数作为参数传递

    public class Tool { public void a()// /方法a { System.out.print("tool.a()..."); } public voi ...

  2. javascript原生ajax;

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. AS3游戏中可视对象上限及位图相关的内存消耗实测

    前些天连续做了一些测试,以加深对AS3的掌握和在项目中对 游戏 性能.效率优化方面的一些处理,有很多测试实际意义不大,都不过是证明一些猜想是正确的,除此没有什么. 但前天进行的一系列测试中,有一些对游 ...

  4. HDU 4914 Linear recursive sequence(矩阵乘法递推的优化)

    题解见X姐的论文 矩阵乘法递推的优化.仅仅是mark一下. .

  5. JVM参数

    下面给出各种可以用户设置堆大小的命令行参数.注释列提供了一些设置参数的初级或高级建议.此外,后面还会给出更多的详细建议. 参数 描述 注释 -Xms<size> 设置堆的最小值 在生产阶段 ...

  6. .net 资源

    基于.net构架的留言板项目大全源码 http://down.51cto.com/zt/70 ASP.net和C#.net通用权限系统组件功能教程 http://down.51cto.com/zt/1 ...

  7. 征服 Redis + Jedis + Spring —— 配置&常规操作

    Spring提供了对于Redis的专门支持:spring-data-redis.此外,类似的还有: 我想大部分人对spring-data-hadoop.spring-data-mongodb.spri ...

  8. Visual Studio之Nuget(服务器)

    一.创建空Web项目 二.安装Nuget.Server 这个时候,安装完成后,发现项目文件里多了Default.aspx等文件,因为我选择的MVC,所以最好做下小小的调整 ——在Global.asax ...

  9. day7_python学习笔记_chapter9_文件

    1. open(), file(), 作用完全相同 2. 语法: file_object = open(file_name, access_mode='r', buffering='-1') acce ...

  10. springmvc中关于静态资源的放行

    参考:http://blog.csdn.net/fujiakai/article/details/52504525 方法1. 修改web.xml文件,增加对静态资源的url映射,要加在org.spri ...