题目描述

一个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<=100)。

操作2:“2 x1 x2 y1 y2 c”(不含双引号,x1<=x2,y1<=y2)。表示询问所有满足格子颜色为c,且x1<=x<=x2,y1<=y<=y2的格子(x,y)的个数。

输出格式:

对于每个操作2,按照在输入中出现的顺序,依次输出一行一个整数表示所求得的个数。

输入输出样例

输入样例#1: 复制

3 3
1 2 3
3 2 1
2 1 3
3
2 1 2 1 2 1
1 2 3 2
2 2 3 2 3 2
输出样例#1: 复制

1
2

说明

数据规模:30%的数据,满足:n,m<=30,Q<=50000

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 200005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-5
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii; inline int rd() {
int x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/
int c[302][310][310];
int a[500][500];
int n, m;
void add(int x, int y,int val,int col) {
for (int i = x; i <= n; i += i & -i) {
for (int j = y; j <= m; j += j & -j) {
c[col][i][j] += val;
}
}
} int query(int x, int y, int col) {
int ans = 0;
for (int i = x; i > 0; i -= i & -i) {
for (int j = y; j > 0; j -= j & -j) {
ans += c[col][i][j];
}
}
return ans;
} int main()
{
//ios::sync_with_stdio(0);
n = rd(); m = rd();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++)a[i][j] = rd(), add(i, j, 1, a[i][j]);
}
int q;
q = rd();
while (q--) {
int opt; opt = rd();
if (opt == 1) {
int x, y, c; x = rd(); y = rd(); c = rd();
add(x, y, -1, a[x][y]); a[x][y] = c; add(x, y, 1, a[x][y]);
}
else {
int a, x, b, y; a = rd(); x = rd(); b = rd(); y = rd();
int c; c = rd();
int ans = query(x, y, c) - query(a - 1, y, c) - query(x, b - 1, c) + query(a - 1, b - 1, c);
printf("%d\n", ans);
}
}
return 0;
}

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

  1. 二维树状数组 BZOJ 1452 [JSOI2009]Count

    题目链接 裸二维树状数组 #include <bits/stdc++.h> const int N = 305; struct BIT_2D { int c[105][N][N], n, ...

  2. 洛谷P4054 [JSOI2009]计数问题(二维树状数组)

    题意 题目链接 Sol 很傻x的题.. c才100, n, m才300,直接开100个二维树状数组就做完了.. #include<bits/stdc++.h> using namespac ...

  3. [JSOI2009]计数问题 二维树状数组

    ---题面--- 题解: 二维树状数组的板子题,,,学了这么久第一次写二维树状数组,惭愧啊. 怎么写就不说了,看代码吧. 跟普通的是一样的写法 #include<bits/stdc++.h> ...

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

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

  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 二维树状数组

    1452: [JSOI2009]Count Description Input Output Sample Input Sample Output 1 2 HINT Source 题解:设定C[101 ...

  8. 模板:二维树状数组 【洛谷P4054】 [JSOI2009]计数问题

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

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

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

随机推荐

  1. obj.get_字段名称_display

    在页面上我们只要这么写就可以直接把字典的值显示出来了 {{ obj.get_level_display }}({{ obj.level }}) obj.get_字段名称_display . model ...

  2. window - BOM对象

    Window 对象 Window 对象表示浏览器中打开的窗口. 如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创建一个 window 对象,并为每个框架创建一个额外 ...

  3. xcode恢复语法高亮

    [xcode恢复语法高亮] 非常简单,在Organizer中删除derivedData.

  4. LED电视与液晶电视的区别

    [LED电视与液晶电视的区别] 目前LED电视全部是采用了LED背光的液晶电视,本质上而言,还是液晶电视.这与真正的LED电视是两个完全不同的概念.如今通常把LED背光电视称为LED电视,采用CCFL ...

  5. jps, jinfo命令

    jps主要用来输出JVM中运行的进程状态信息. -q 不输出类名.Jar名和传入main方法的参数 -m 输出传入main方法的参数 -l 输出main类或Jar的全限名 -v 输出传入JVM的参数 ...

  6. 734. Sentence Similarity 有字典数组的相似句子

    [抄题]: Given two sentences words1, words2 (each represented as an array of strings), and a list of si ...

  7. 一次shell中seq的处理

    一次shell中seq的处理 背景:用要shell 提取 文件中内容,文件名是用序列号如下生成,文件差不多有将近400多w个  如下:  www.ahlinux.com 原始脚本#! /bin/sh# ...

  8. c语言实践 打印数字三角形

    效果如下图: 思路就是外层循环控制要打印的行数,里层循环控制每行打印的数字个数. int val = 65; for (int i = 0; i < 6; i++) { for (int j = ...

  9. 数字图像处理实验(17):PROJECT 06-04,Color Image Segmentation 标签: 图像处理MATLAB 2017-05-27 21:13

    实验报告: Objective: Color image segmentation is a big issue in image processing. This students need to ...

  10. Nhibernate HQL 匿名类(严格说是map的使用以及构造函数的使用

    1.map的使用 var hql=string.Format(@"select new map( tc.LimitIndexType as LimitIndexType, tc.LimitS ...