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

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

#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. 灵活运用Zend框架

    $aAwardMem = $this->dao_raward->getAwardAndMem($where,'award_level asc',false,false,false,'awa ...

  2. POJ1185 炮兵阵地 状态压缩

    因为不知道不同的博客怎么转,就把别人的复制过来了,这个题解写的非常好,原地址为: http://hi.baidu.com/wangxustf/item/9138f80ce2292b8903ce1bc7 ...

  3. Error copying image in the datastore: Not allowed to copy image file

    opennebula error copying image in the datastore not allowed to copy image file Error copying image i ...

  4. jeecms 2012 源码分析(2) 前台栏目页静态化分析

    还是要说到web.xml文件 <welcome-file-list> <welcome-file>index.html</welcome-file> <wel ...

  5. javascript模块化开发编程

    随着网站的不断迭代更新,js代码越来越多,那么问题来了 代码比较乱 命名出现冲突 文件依赖比较繁杂 为了解决以上问题,模块化开发出现了 1.一个简单的demo,维护和扩展模块 模块的维护和扩展一定要遵 ...

  6. param

    页面之间值传递用param作为参数,提高网站安全性

  7. Linux 文件内容转码

    文件内容的转换: iconv -f GB2312 -t UTF-8 gb1.txt >gb2.txt-f, –from-code=名称 原始文本编码-t, –to-code=名称 输出编码-o, ...

  8. Hibernate工作流程

    Hibernate创建步骤 (五大核心接口:Configuration/SessionFactory/Session/Transaction/Query) 1.新建工程,导入需要的jar包. 2.利用 ...

  9. iOS 导航条的影响

    如果是push出来的控制器,self.view的(0,0)点从状态栏下面开始: 如果有present出来的控制器,self.view的(0,0)点包含状态栏:

  10. MarkDown使用 (三)表格

    MarkDown表格的用法 MarkDown表格的用法 例如: $$ \begin{array}{c|lcr} n & \text{Left} & \text{Center} & ...