二维树状数组 BZOJ 1452 [JSOI2009]Count
裸二维树状数组
- #include <bits/stdc++.h>
- const int N = 305;
- struct BIT_2D {
- int c[105][N][N], n, m;
- void init(int n, int m) {
- memset (c, 0, sizeof (c));
- this->n = n;
- this->m = m;
- }
- void updata(int k, int x, int y, int z) {
- for (int i=x; i<=n; i+=i&(-i)) {
- for (int j=y; j<=m; j+=j&(-j)) {
- c[k][i][j] += z;
- }
- }
- }
- int query(int k, int x, int y) {
- int ret = 0;
- for (int i=x; i; i-=i&(-i)) {
- for (int j=y; j; j-=j&(-j)) {
- ret += c[k][i][j];
- }
- }
- return ret;
- }
- int count(int x1, int x2, int y1, int y2, int a) {
- return query (a, x2, y2) - query (a, x2, y1-1) - query (a, x1-1, y2) + query (a, x1-1, y1-1);
- }
- };
- int a[N][N];
- BIT_2D bit;
- int read() {
- int ret = 0, f = 1;
- char ch = getchar ();
- while (ch < '0' || ch > '9') {
- if (ch == '-') {
- f = -1;
- }
- ch = getchar ();
- }
- while (ch >= '0' && ch <= '9') {
- ret = ret * 10 + ch - '0';
- ch = getchar ();
- }
- return ret * f;
- }
- int main() {
- int n, m;
- while (scanf ("%d%d", &n, &m) == 2) {
- bit.init (n, m);
- for (int i=1; i<=n; ++i) {
- for (int j=1; j<=m; ++j) {
- //scanf ("%d", &a[i][j]);
- a[i][j] = read ();
- bit.updata (a[i][j], i, j, 1);
- }
- }
- int q;
- scanf ("%d", &q);
- while (q--) {
- int op, x1, x2, y1, y2, x;
- scanf ("%d", &op);
- if (op == 1) {
- //scanf ("%d%d%d", &x1, &y1, &x);
- x1 = read (); y1 = read (); x = read ();
- bit.updata (a[x1][y1], x1, y1, -1);
- a[x1][y1] = x;
- bit.updata (a[x1][y1], x1, y1, 1);
- } else {
- //scanf ("%d%d%d%d%d", &x1, &x2, &y1, &y2, &x);
- x1 = read (); x2 = read (); y1 = read (); y2 = read (); x = read ();
- printf ("%d\n", bit.count (x1, x2, y1, y2, x));
- }
- }
- }
- return 0;
- }
二维树状数组 BZOJ 1452 [JSOI2009]Count的更多相关文章
- 【二维树状数组】bzoj1452 [JSOI2009]Count
权值的种类只有100种,对每种开个二维BIT,然后是经典操作. #include<cstdio> using namespace std; ][]; struct BIT_2D { ][] ...
- [JSOI2009]计数问题 二维树状数组BZOJ 1452
题目描述 一个n*m的方格,初始时每个格子有一个整数权值.接下来每次有2种操作: 改变一个格子的权值: 求一个子矩阵中某种特定权值出现的个数. 输入输出格式 输入格式: 第一行有两个数N,M. 接下来 ...
- 【二维树状数组】计数问题 @JSOI2009/upcexam5911
时间限制: 1 Sec 内存限制: 128 MB 题目描述 一个n*m的方格,初始时每个格子有一个整数权值.接下来每次有2种操作: 改变一个格子的权值: 求一个子矩阵中某种特定权值出现的个数. 输入 ...
- bzoj 1452: [JSOI2009]Count (二维树状数组)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1452 思路: 对每个颜色开一个二维树状数组维护就好了 实现代码: #include<b ...
- bzoj 1452: [JSOI2009]Count ——二维树状数组
escription Input Output Sample Input Sample Output 1 2 HINT ———————————————————————————————————————— ...
- BZOJ 1452 Count(二维树状数组)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1452 题意:给出一个数字矩阵(矩阵中任何时候的数字均为[1,100]),两种操作:(1) ...
- BZOJ 1452 Count(二维树状数组)
大水题. 建立100个二维树状数组,总复杂度就是O(qlognlogm). # include <cstdio> # include <cstring> # include & ...
- BZOJ 1452 Count 【模板】二维树状数组
对每种颜色开一个二维树状数组 #include<cstdio> #include<algorithm> using namespace std; ; ][maxn][maxn] ...
- BZOJ.2738.矩阵乘法(整体二分 二维树状数组)
题目链接 BZOJ 洛谷 整体二分.把求序列第K小的树状数组改成二维树状数组就行了. 初始答案区间有点大,离散化一下. 因为这题是一开始给点,之后询问,so可以先处理该区间值在l~mid的修改,再处理 ...
随机推荐
- Android开发之《常用工具及文档汇总》
GreenVPN:https://www.getgreenjsq.com/ Android开发工具.资料下载汇总:http://androiddevtools.cn/#img-size-handle- ...
- IOS定位
#import "ViewController.h" #import <CoreLocation/CoreLocation.h> @interface ViewCont ...
- Kakfa重连测试
在Kafak已启动的情况下: 发送端首次连接大概耗时400毫秒.后续消息发送都在1毫秒以下. 接收端首次连接大概耗时400-7000毫秒.后续消息接收都在1毫秒以下.(具体时间与topic中存留的消息 ...
- 裁剪要素出现错误 :HRESULT:0x80040239
pFeatureBuffer = pOutFeaCls.CreateFeatureBuffer(); pFeatureCursor = pOutFeaCls.Inser ...
- lucene大索引文件分布式存储方案
这几天实现了个Lucene分布式检索的模块,采用的分布式方案是将数据分块,分别生成N个索引文件,放到N个节点上运行.检索时,对每一个节点发出查询请求,将N个节点返回的结果归并,然后生成一个新的结果.如 ...
- [java] 可视化日历的实现(基于Calendar类 )
写在前面 博文安排顺序如下 1.写在前面 2.源码 3.思路 4.相关知识 该小程序是对Date类及其相关类的复习 要求如下图:实现可视化日历 实现思路 1.先从键盘输入指定格式的字符串(str)2. ...
- JDK Collection 源码分析(1)—— Collection
JDK Collection JDK Collection作为一个最顶层的接口(root interface),JDK并不提供该接口的直接实现,而是通过更加具体的子接口(sub interface ...
- LYDSY模拟赛day1 Tourist Attractions
/* 假设路径是 a − b − c − d,考虑枚举中间这条边 b − c,计 算有多少可行的 a 和 d. 设 degx 表示点 x 的度数,那么边 b − c 对答案的贡献为 (degb − 1 ...
- iOS开发UI中懒加载的使用方法
1.懒加载基本 懒加载——也称为延迟加载,即在需要的时候才加载(效率低,占用内存小).所谓懒加载,写的是其getter方法.说的通俗一点,就是在开发中,当程序中需要利用的资源时.在程序启动的时候不加载 ...
- UVALive 4329 Ping pong
Ping pong Time Limit: 3000MS Memory Limit: Unknown 64bit IO Fo ...