题目链接

裸二维树状数组

  1. #include <bits/stdc++.h>
  2.  
  3. const int N = 305;
  4. struct BIT_2D {
  5. int c[105][N][N], n, m;
  6. void init(int n, int m) {
  7. memset (c, 0, sizeof (c));
  8. this->n = n;
  9. this->m = m;
  10. }
  11. void updata(int k, int x, int y, int z) {
  12. for (int i=x; i<=n; i+=i&(-i)) {
  13. for (int j=y; j<=m; j+=j&(-j)) {
  14. c[k][i][j] += z;
  15. }
  16. }
  17. }
  18. int query(int k, int x, int y) {
  19. int ret = 0;
  20. for (int i=x; i; i-=i&(-i)) {
  21. for (int j=y; j; j-=j&(-j)) {
  22. ret += c[k][i][j];
  23. }
  24. }
  25. return ret;
  26. }
  27. int count(int x1, int x2, int y1, int y2, int a) {
  28. return query (a, x2, y2) - query (a, x2, y1-1) - query (a, x1-1, y2) + query (a, x1-1, y1-1);
  29. }
  30. };
  31.  
  32. int a[N][N];
  33. BIT_2D bit;
  34.  
  35. int read() {
  36. int ret = 0, f = 1;
  37. char ch = getchar ();
  38. while (ch < '0' || ch > '9') {
  39. if (ch == '-') {
  40. f = -1;
  41. }
  42. ch = getchar ();
  43. }
  44. while (ch >= '0' && ch <= '9') {
  45. ret = ret * 10 + ch - '0';
  46. ch = getchar ();
  47. }
  48. return ret * f;
  49. }
  50.  
  51. int main() {
  52. int n, m;
  53. while (scanf ("%d%d", &n, &m) == 2) {
  54. bit.init (n, m);
  55. for (int i=1; i<=n; ++i) {
  56. for (int j=1; j<=m; ++j) {
  57. //scanf ("%d", &a[i][j]);
  58. a[i][j] = read ();
  59. bit.updata (a[i][j], i, j, 1);
  60. }
  61. }
  62. int q;
  63. scanf ("%d", &q);
  64. while (q--) {
  65. int op, x1, x2, y1, y2, x;
  66. scanf ("%d", &op);
  67. if (op == 1) {
  68. //scanf ("%d%d%d", &x1, &y1, &x);
  69. x1 = read (); y1 = read (); x = read ();
  70. bit.updata (a[x1][y1], x1, y1, -1);
  71. a[x1][y1] = x;
  72. bit.updata (a[x1][y1], x1, y1, 1);
  73. } else {
  74. //scanf ("%d%d%d%d%d", &x1, &x2, &y1, &y2, &x);
  75. x1 = read (); x2 = read (); y1 = read (); y2 = read (); x = read ();
  76. printf ("%d\n", bit.count (x1, x2, y1, y2, x));
  77. }
  78. }
  79. }
  80. return 0;
  81. }

  

二维树状数组 BZOJ 1452 [JSOI2009]Count的更多相关文章

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

    权值的种类只有100种,对每种开个二维BIT,然后是经典操作. #include<cstdio> using namespace std; ][]; struct BIT_2D { ][] ...

  2. [JSOI2009]计数问题 二维树状数组BZOJ 1452

    题目描述 一个n*m的方格,初始时每个格子有一个整数权值.接下来每次有2种操作: 改变一个格子的权值: 求一个子矩阵中某种特定权值出现的个数. 输入输出格式 输入格式: 第一行有两个数N,M. 接下来 ...

  3. 【二维树状数组】计数问题 @JSOI2009/upcexam5911

    时间限制: 1 Sec 内存限制: 128 MB 题目描述 一个n*m的方格,初始时每个格子有一个整数权值.接下来每次有2种操作: 改变一个格子的权值: 求一个子矩阵中某种特定权值出现的个数. 输入 ...

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

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

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

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

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

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1452 题意:给出一个数字矩阵(矩阵中任何时候的数字均为[1,100]),两种操作:(1) ...

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

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

  8. BZOJ 1452 Count 【模板】二维树状数组

    对每种颜色开一个二维树状数组 #include<cstdio> #include<algorithm> using namespace std; ; ][maxn][maxn] ...

  9. BZOJ.2738.矩阵乘法(整体二分 二维树状数组)

    题目链接 BZOJ 洛谷 整体二分.把求序列第K小的树状数组改成二维树状数组就行了. 初始答案区间有点大,离散化一下. 因为这题是一开始给点,之后询问,so可以先处理该区间值在l~mid的修改,再处理 ...

随机推荐

  1. Android开发之《常用工具及文档汇总》

    GreenVPN:https://www.getgreenjsq.com/ Android开发工具.资料下载汇总:http://androiddevtools.cn/#img-size-handle- ...

  2. IOS定位

    #import "ViewController.h" #import <CoreLocation/CoreLocation.h> @interface ViewCont ...

  3. Kakfa重连测试

    在Kafak已启动的情况下: 发送端首次连接大概耗时400毫秒.后续消息发送都在1毫秒以下. 接收端首次连接大概耗时400-7000毫秒.后续消息接收都在1毫秒以下.(具体时间与topic中存留的消息 ...

  4. 裁剪要素出现错误 :HRESULT:0x80040239

    pFeatureBuffer = pOutFeaCls.CreateFeatureBuffer();                 pFeatureCursor = pOutFeaCls.Inser ...

  5. lucene大索引文件分布式存储方案

    这几天实现了个Lucene分布式检索的模块,采用的分布式方案是将数据分块,分别生成N个索引文件,放到N个节点上运行.检索时,对每一个节点发出查询请求,将N个节点返回的结果归并,然后生成一个新的结果.如 ...

  6. [java] 可视化日历的实现(基于Calendar类 )

    写在前面 博文安排顺序如下 1.写在前面 2.源码 3.思路 4.相关知识 该小程序是对Date类及其相关类的复习 要求如下图:实现可视化日历 实现思路 1.先从键盘输入指定格式的字符串(str)2. ...

  7. JDK Collection 源码分析(1)—— Collection

    JDK Collection   JDK Collection作为一个最顶层的接口(root interface),JDK并不提供该接口的直接实现,而是通过更加具体的子接口(sub interface ...

  8. LYDSY模拟赛day1 Tourist Attractions

    /* 假设路径是 a − b − c − d,考虑枚举中间这条边 b − c,计 算有多少可行的 a 和 d. 设 degx 表示点 x 的度数,那么边 b − c 对答案的贡献为 (degb − 1 ...

  9. iOS开发UI中懒加载的使用方法

    1.懒加载基本 懒加载——也称为延迟加载,即在需要的时候才加载(效率低,占用内存小).所谓懒加载,写的是其getter方法.说的通俗一点,就是在开发中,当程序中需要利用的资源时.在程序启动的时候不加载 ...

  10. UVALive 4329 Ping pong

                                      Ping pong Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Fo ...