Count(二维树状数组)
【bzoj1452】[JSOI2009]Count
Description

Input

Output

Sample Input
Sample Output
2
HINT

题解:对于每一个颜色建一个二维的树状数组O(c*logn*logm),试了试对每个颜色,每行建一个一维数组,超时了。。。O(c*n*logm)
若一维树状数组不会:http://www.cnblogs.com/haoabcd2010/p/6657393.html
#include <iostream>
#include <stdio.h>
#include <string.h> using namespace std;
#define MAXN 302 int n,m;
int G[MAXN][MAXN];
int tree[][MAXN][MAXN]; // 颜色,行,列 int lowbit(int x) {return x&(-x);} void update(int c,int x,int y,int add)
{
for(int i=x;i<=n;i+=lowbit(i))
for (int j=y;j<=m;j+=lowbit(j))
tree[c][i][j]+=add;
} int getsum(int c,int x,int y)
{
int ans =;
for (int i=x;i>;i-=lowbit(i))
for (int j=y;j>;j-=lowbit(j))
ans += tree[c][i][j];
return ans;
} int main()
{
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
scanf("%d",&G[i][j]); for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
update(G[i][j],i,j,); int q;
scanf("%d",&q);
while (q--)
{
int op;
scanf("%d",&op);
if (op==)
{
int x,y,c;
scanf("%d%d%d",&x,&y,&c);
update(c,x,y,);//c颜色x,y +1
update(G[x][y],x,y,-);//原来颜色xy -1
G[x][y]=c;
}
if (op==)
{
int x1,x2,y1,y2,c;
scanf("%d%d%d%d%d",&x1,&x2,&y1,&y2,&c);
int ans = getsum(c,x2,y2)+getsum(c,x1-,y1-); //c 颜色 i行y1-y2;
ans -= getsum(c,x1-,y2);
ans -= getsum(c,x2,y1-);
printf("%d\n",ans);
}
}
return ;
}
Count(二维树状数组)的更多相关文章
- bzoj1452 [JSOI2009]Count ——二维树状数组
中文题面,给你一个矩阵,每一个格子有数字,有两种操作. 1. 把i行j列的值更改 2. 询问两个角坐标分别为(x1,y1) (x2,y2)的矩形内有几个值为z的点. 这一题的特点就是给出的z的数据范围 ...
- BZOJ 1452 Count(二维树状数组)
大水题. 建立100个二维树状数组,总复杂度就是O(qlognlogm). # include <cstdio> # include <cstring> # include & ...
- bzoj 1452: [JSOI2009]Count ——二维树状数组
escription Input Output Sample Input Sample Output 1 2 HINT ———————————————————————————————————————— ...
- 【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 ...
- 二维树状数组 BZOJ 1452 [JSOI2009]Count
题目链接 裸二维树状数组 #include <bits/stdc++.h> const int N = 305; struct BIT_2D { int c[105][N][N], n, ...
- BZOJ 1452 Count(二维树状数组)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1452 题意:给出一个数字矩阵(矩阵中任何时候的数字均为[1,100]),两种操作:(1) ...
- bzoj 1452: [JSOI2009]Count (二维树状数组)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1452 思路: 对每个颜色开一个二维树状数组维护就好了 实现代码: #include<b ...
- BZOJ 1452 Count 【模板】二维树状数组
对每种颜色开一个二维树状数组 #include<cstdio> #include<algorithm> using namespace std; ; ][maxn][maxn] ...
随机推荐
- 超级惊艳 10款HTML5动画特效推荐[转]
ylbtech_html5_demo 今天我们要来推荐 10 款超级惊艳的 HTML5 动画特效,有一些是基于 CSS3 和 jQuery 的,比较实用,特别是前几个 HTML5 动画,简直酷毙了,现 ...
- angular 中的$event 对象包含了浏览器原生的event对象
ou can pass the $event object as an argument when calling the function. The $event object contains t ...
- UVa 10192 - Vacation & UVa 10066 The Twin Towers ( LCS 最长公共子串)
链接:UVa 10192 题意:给定两个字符串.求最长公共子串的长度 思路:这个是最长公共子串的直接应用 #include<stdio.h> #include<string.h> ...
- Spring管理的bean初始化方法的三种方式,以及@PostConstruct不起作用的原因
1:Spring 容器中的 Bean 是有生命周期的,spring 允许 Bean 在初始化完成后以及销毁前执行特定的操作.下面是常用的三种指定特定操作的方法: 通过实现InitializingBea ...
- 使用Spring开发和监控线程池服务
第1步:添加maven 项目 第2步:添加依赖库 将Spring的依赖添加到Maven的pom.xml文件中. 1 2 3 4 5 6 7 8 9 10 11 <!-- Spring 3 dep ...
- POJ 1040 Transportation
链接:http://poj.org/problem?id=1040 Transportation Time Limit: 1000MS Memory Limit: 10000K Total Submi ...
- 载入本地Html文件
NSString * resousePath = [[NSBundle mainBundle]resourcePath]; NSString * filePath = [resouse ...
- 【转载】 json字符串与JSON对象
ajax中,我们自己拼接的是一个JSON对象,以为它是无数据类型的,所以JS根据其格式默认其实对象, 你要是往后台发,要先把它装换成JSON字符. 从ajax的服务器发过的,一定是字符串,你想要把它解 ...
- 斯坦福《机器学习》Lesson5感想———1、成学习算法
在前面几课里的学习算法的思路都是给定数据集以后.确定基于此数据集的最佳如果H函数,通过学习算法确定最佳如果H的各个參数,然后通过最佳如果函数H得出新的数据集的结果.在这一课里介绍了一种新的思路,它的核 ...
- 斯坦福《机器学习》Lesson4感想--1、Logistic回归中的牛顿方法
在上一篇中提到的Logistic回归是利用最大似然概率的思想和梯度上升算法确定θ,从而确定f(θ).本篇将介绍还有一种求解最大似然概率ℓ(θ)的方法,即牛顿迭代法. 在牛顿迭代法中.如果一个函数是,求 ...