[JSOI2009]计数问题 二维树状数组BZOJ 1452
题目描述
一个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,按照在输入中出现的顺序,依次输出一行一个整数表示所求得的个数。
输入输出样例
说明
数据规模: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的更多相关文章
- 二维树状数组 BZOJ 1452 [JSOI2009]Count
题目链接 裸二维树状数组 #include <bits/stdc++.h> const int N = 305; struct BIT_2D { int c[105][N][N], n, ...
- 洛谷P4054 [JSOI2009]计数问题(二维树状数组)
题意 题目链接 Sol 很傻x的题.. c才100, n, m才300,直接开100个二维树状数组就做完了.. #include<bits/stdc++.h> using namespac ...
- [JSOI2009]计数问题 二维树状数组
---题面--- 题解: 二维树状数组的板子题,,,学了这么久第一次写二维树状数组,惭愧啊. 怎么写就不说了,看代码吧. 跟普通的是一样的写法 #include<bits/stdc++.h> ...
- bzoj 1452: [JSOI2009]Count ——二维树状数组
escription Input Output Sample Input Sample Output 1 2 HINT ———————————————————————————————————————— ...
- bzoj1452 [JSOI2009]Count ——二维树状数组
中文题面,给你一个矩阵,每一个格子有数字,有两种操作. 1. 把i行j列的值更改 2. 询问两个角坐标分别为(x1,y1) (x2,y2)的矩形内有几个值为z的点. 这一题的特点就是给出的z的数据范围 ...
- 【bzoj1452】[JSOI2009]Count 二维树状数组
题目描述 输入 输出 样例输入 样例输出 1 2 题解 二维树状数组 一开始没看到 1≤c≤100 ,想到了主X树和X块,结果发现c的范围那么小... 二维树状数组水题,和一维的一样,向上修改,向下查 ...
- BZOJ 1452: [JSOI2009]Count 二维树状数组
1452: [JSOI2009]Count Description Input Output Sample Input Sample Output 1 2 HINT Source 题解:设定C[101 ...
- 模板:二维树状数组 【洛谷P4054】 [JSOI2009]计数问题
P4054 [JSOI2009]计数问题 题目描述 一个n*m的方格,初始时每个格子有一个整数权值.接下来每次有2种操作: 改变一个格子的权值: 求一个子矩阵中某种特定权值出现的个数. 输入输出格式 ...
- bzoj 1452: [JSOI2009]Count (二维树状数组)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1452 思路: 对每个颜色开一个二维树状数组维护就好了 实现代码: #include<b ...
随机推荐
- go语言 robfig/cron包 实现定时 调用
package main import ( "github.com/robfig/cron" "time" "fmt" "os&q ...
- UIWidget
[UIWidget] UIWidget在NGUI中的层次如下. 根据上篇所述,UIRect实现实现了Anchor功能.而Widget提供的功能也很简单,如下: 可以看到,widget只提供四个属性,a ...
- day63-webservice 03.解析cxf提供的例子
Path配置: C:\Program Files (x86)\ScanSign;E:\app\zhongzh\product\11.2.0\dbhome_1\bin;D:\app\zhongzh\pr ...
- Jquery异步
一.Jquery向aspx页面请求数据$("#Button1").bind("click", function () { $.ajax({ type: &quo ...
- Linux 常用基本命令1
linux终端 linux有6个终端 alt+f1 -f6 切换各个终端 这样有个好处,可以用多个终端同时做事情,一个终端死掉,也可以换另外的终端 cd / 根目录 ls 蓝色的目录 白色是文件 c ...
- Linux常用基本命令 1
useradd 创建用户. password 修改密码. date 查看时间 man date 帮助文档.f往后翻 b往前翻 q退出.软修改 man hwclock 修改硬件时钟, cal 查看日历 ...
- SQL Server CLR全功略之一---CLR介绍和配置
Microsoft SQL Server 现在具备与 Microsoft Windows .NET Framework 的公共语言运行时 (CLR) 组件集成的功能.CLR 为托管代码提供服务,例如跨 ...
- opennebule 创建cdrom数据发送
{","csrftoken":"b9b5026f1a92180b789971ed8e21d28b"}
- 面试题:TCP协议三次握手
一.首先了解TCP报文格式 其中必须了解的字段有: 1.源端口与目的端口:16位,标识出发送端与接收端的端口号. 2.序号:32位,也叫顺序号.seg序号,本报文段所发送的数据的第一个字节的序号,用来 ...
- 453D Little Pony and Elements of Harmony
传送门 分析 我们可以将所有的b[i^j]直接对应到b[f(i^j)]上 于是显然可以fwt 我们对b进行t次fwt之后直接将答案与e0卷起来即可 注意由于模数不确定,我们可以将模数扩大$2^m$然后 ...