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

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

#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. POJ 2799 IP Networks

    network address是前(32-n)随意 后n位全零 network mask是前(32-n)全一 后n位全零 本题主要利用位移操作,1ULL表示无符号长整型的常数1,这样写可防止不必要的溢 ...

  2. OpenNebula openldap集成

    Preface: 当前写这篇post的心情可谓是即激动,又操蛋!............................ ruiy还是言归正传,人老了,赖的扯淡了,哥当前一心看向Tech(s),做个顾 ...

  3. mac文件权限

    如何设置文件/或文件夹权限为777 进入终端,切换到指定目录,输入以下命令,后面添加你的文件名/目录名$sudo chmod -R 777 (文件名/目录名) 或 $chmod 777 ./test. ...

  4. css滤镜(转载)

    STYLE="filter:filtername(fparameter1, fparameter2...)" (Filtername为滤镜的名称,fparameter1.fpara ...

  5. XX cannot be resolved to a type

    http://www.cnblogs.com/xuxm2007/archive/2011/10/20/2219104.html 我是project->clean...即可 原理:将工程中的.cl ...

  6. log4j.xml配置示例

    这是log4j1.x版本讲解,log4j-1.2.16.jar    1. 一般的log4j.xml的两种配置方式: 1.Logger 完成日志信息的处理定义输出的层次和决定信息是否输出DEBUG&l ...

  7. 微信支付java版V3验证数据合法性

    [TOC] 1. 微信支付java版V3验证数据合法性 概要:使用微信支付接口时,微信会返回或回调给商户XML数据,开发者需要验证微信返回的数据是否合法. 特别提醒:商户系统对于支付结果通知的内容一定 ...

  8. STL模板_容器概念

    一.STL(Standard Template Library,标准模板库)概述1.容器:基于泛型的数据结构.2.算法:基于泛型的常用算法.3.迭代器:以泛型的方式访问容器中的元素,是泛型的算法可以应 ...

  9. ThinkPHP第二十三天(Category表结构、PHPExcel导入数据函数)

    1.category分类表表结构id,name,pid,sort,结合category.class.php类使用. 2.PHPExcel导入数据函数示例 function excel_to_mysql ...

  10. NETTY 编码器介绍

    1. 背景 1.1. 编解码技术 通常我们也习惯将编码(Encode)称为序列化(serialization),它将对象序列化为字节数组,用于网络传输.数据持久化或者其它用途. 反之,解码(Decod ...