【bzoj1452】[JSOI2009]Count

Description

Input

Output

Sample Input

Sample Output

1
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(二维树状数组)的更多相关文章

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

    中文题面,给你一个矩阵,每一个格子有数字,有两种操作. 1. 把i行j列的值更改 2. 询问两个角坐标分别为(x1,y1) (x2,y2)的矩形内有几个值为z的点. 这一题的特点就是给出的z的数据范围 ...

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

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

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

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

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

    题目描述 输入 输出 样例输入 样例输出 1 2 题解 二维树状数组 一开始没看到 1≤c≤100 ,想到了主X树和X块,结果发现c的范围那么小... 二维树状数组水题,和一维的一样,向上修改,向下查 ...

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. 2017.9.5 postgresql加密函数的使用

    需要安装的插件的名字:pgcrypto 官网地址:https://www.postgresql.org/docs/9.4/static/pgcrypto.html stackoverflow: htt ...

  2. Elasticsearch 基础使用

    使用 cURL 执行 REST 命令 可以对 Elasticsearch 发出 cURL 请求,这样很容易从命令行 shell 体验该框架. “Elasticsearch 是无模式的.它可以接受您提供 ...

  3. Angular 学习笔记——run

    <!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <met ...

  4. C++ 大规模数据排序(100G数据 使用 4G 内存 排序)

    思路很简单,先分段排序,存储到临时文件中,然后合并. 使用10000个整数来模拟大数据,每次读取100个到内存中. #include <stdint.h> #include <std ...

  5. Python_Select解析

    selcet(等待I/O完成)的介绍: select同时监控多个socket,select()的机制提供了fd_set的数据结构,实际是long类型的数组,优点是跨平台性,select的缺点在于单个进 ...

  6. python——双下划线与python命名机制

    python中双下划线的作用(1)所有以双下划线开头的成员是私有的(2)python对于私有变量是会进行扎压(mangling)的,扎压规则是原始定义:class A():    __function ...

  7. vue-router push

    //push 方法一 对象 // this.$router.push({path:'HelloWorld2'}); //push 方法二 命名的路由 // this.$router.push({nam ...

  8. 【BIEE】分析的解析机制

    今天使用BIEE时意外的发现个问题,BIEE在展示结果时候,是先进行排序,然后再展示.具体测试案例如下: 首先,存在如下数据: 在BIEE展示效果如下: 目前是根据O1,02,03,04,05,06, ...

  9. 关于 Nginx 并发连接数

    关于 Nginx 并发连接数 最近在学习使用 nginx , 做一些简单的压力测试时,发现并发连接数最大只能上到 100 多 测试刚开始时的状态 , netstat -n | awk '/^tcp/ ...

  10. Calculation 2-欧拉函数的运用

    Calculation 2 Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit ...