中文题面,给你一个矩阵,每一个格子有数字,有两种操作. 1. 把i行j列的值更改 2. 询问两个角坐标分别为(x1,y1) (x2,y2)的矩形内有几个值为z的点. 这一题的特点就是给出的z的数据范围很小,只有1~100,所以我们可以开100个300X300的二维树状数组来解决问题. #include<bits/stdc++.h> using namespace std; ][][]; ][]; int n,m,k; int lowbit(int x) { return x&-x; }…
题目描述 输入 输出 样例输入 样例输出 1 2 题解 二维树状数组 一开始没看到 1≤c≤100 ,想到了主X树和X块,结果发现c的范围那么小... 二维树状数组水题,和一维的一样,向上修改,向下查询,把一个范围变为4个范围处理. #include <cstdio> int a[310][310] , f[110][310][310] , n , m; void update(int p , int x , int y , int a) { int i , j; for(i = x ; i…
题目链接 裸二维树状数组 #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;…
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1452 思路: 对每个颜色开一个二维树状数组维护就好了 实现代码: #include<bits/stdc++.h> using namespace std; ][][]; ][],n,m,q; int lowbit(int x){ return x&-x; } void add(int x,int y,int z,int rt){ for(int i = x;i <= n;i…
escription Input Output Sample Input Sample Output 1 2 HINT —————————————————————————————————————————— 这道题是裸的二维树状数组.....直接每个颜色弄一个二维的树状数组然后容斥(也不知道算不算)就可以辣 #include<cstdio> #include<cstring> #include<algorithm> int read(){ ,f=,c=getchar();…
P4054 [JSOI2009]计数问题 题目描述 一个n*m的方格,初始时每个格子有一个整数权值.接下来每次有2种操作: 改变一个格子的权值: 求一个子矩阵中某种特定权值出现的个数. 输入输出格式 输入格式: 第一行有两个数N,M. 接下来N行,每行M个数,第i+1行第j个数表示格子(i,j)的初始权值. 接下来输入一个整数Q. 之后Q行,每行描述一个操作. 操作1:"1 x y c"(不含双引号).表示将格子(x,y)的权值改成c(1<=x<=n,1<=y<…
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1452 题意:给出一个数字矩阵(矩阵中任何时候的数字均为[1,100]),两种操作:(1)修改某个位置的数字:(2)求某个子矩阵中某个数字的个数. 思路:二维树状数组的操作看起来跟一维的差不多,只是循环改为两重而已.主要操作有:(1)增加某个位置的值:(2)询问[1,1,x,y]子矩阵的和.利用(2)操作以及区间的减法操作我们能求出任意一个子矩阵的数字和.这道题用a[i][x][y]来记…
时间限制: 1 Sec 内存限制: 128 MB 题目描述 一个n*m的方格,初始时每个格子有一个整数权值.接下来每次有2种操作: 改变一个格子的权值: 求一个子矩阵中某种特定权值出现的个数. 输入 第一行有两个数n,m. 接下来n行,每行m个数,第i+1行第j个数表示格子(i,j)的初始权值. 接下来输入一个整数q. 接下来q行,每行描述一个操作. 操作1:“1 x y c”(不含双引号).表示将格子(x,y)的权值改成c(1<=x<=n,1<=y<=m,1<=c<=…
题意 题目链接 Sol 很傻x的题.. c才100, n, m才300,直接开100个二维树状数组就做完了.. #include<bits/stdc++.h> using namespace std; const int MAXN = 301; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();…
大水题. 建立100个二维树状数组,总复杂度就是O(qlognlogm). # include <cstdio> # include <cstring> # include <cstdlib> # include <iostream> # include <vector> # include <queue> # include <stack> # include <map> # include <set&…