1452: [JSOI2009]Count

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 2419  Solved: 1403
[Submit][Status][Discuss]

Description

Input

Output

Sample Input

Sample Output

1
2

HINT

裸的二维树状数组。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define lowbit(a) ((a) & (-(a))) int read()
{
int x = 0;char ch = getchar();char c = ch;
while(ch > '9' || ch < '0')c = ch, ch = getchar();
while(ch <= '9' && ch >= '0')x = x * 10 + ch - '0', ch = getchar();
if(c == '-')return -x;
return x;
}
const int INF = 0x3f3f3f3f;
const int MAXC = 100 + 10;
const int MAXN = 300 + 10;
const int MAXM = 300 + 10; int n,m;
int data[MAXC][MAXN][MAXM]; int q;
int g[MAXN][MAXM];
int tmp1,tmp2,tmp3,tmp4,tmp5,tmp;
void prin();
int ask(int x,int y,int c)
{
int sum = 0;
for(;x;x -= lowbit(x))
for(int i = y;i;i -= lowbit(i))
sum += data[c][x][i];
return sum;
} int ask(int x1, int y1, int x2, int y2, int c)//左上角,右下角
{
return ask(x2,y2,c) - ask(x2, y1 - 1, c) - ask(x1 - 1, y2, c) + ask(x1 - 1, y1 - 1, c);
} void modify(int x,int y,int c, int num)
{
for(;x <= n;x += lowbit(x))
for(int i = y;i <= m;i += lowbit(i))
data[c][x][i] += num;
}
int main()
{
n = read();m = read();
for(int i = 1;i <= n;i ++)
{
for(int j = 1;j <= m;j ++)
{
tmp = read();
modify(i, j, tmp, 1);
g[i][j] = tmp;
}
}
q = read();
for(int i = 1;i <= q;i ++)
{
tmp = read();
if(tmp == 1)
{
tmp1 = read();tmp2 = read();tmp3 = read();
modify(tmp1, tmp2, g[tmp1][tmp2], -1);
modify(tmp1, tmp2, tmp3, 1);
g[tmp1][tmp2] = tmp3;
}
if(tmp == 2)
{
tmp1 = read();tmp2 = read();tmp3 = read();tmp4 = read();tmp5 = read();
printf("%d\n", ask(tmp1,tmp3,tmp2,tmp4,tmp5));
}
}
return 0;
}

BZOJ1452 [JSOI2009]Count [2017年4月计划 树状数组02]的更多相关文章

  1. 【BZOJ3333】排队计划 树状数组+线段树

    [BZOJ3333]排队计划 Description Input Output Sample Input 6 2 160 163 164 161 167 160 2 3 Sample Output 6 ...

  2. 洛谷P2982 [USACO10FEB]慢下来Slowing down [2017年四月计划 树状数组01]

    P2982 [USACO10FEB]慢下来Slowing down 题目描述 Every day each of Farmer John's N (1 <= N <= 100,000) c ...

  3. BZOJ 3333 排队计划 树状数组+线段树

    题目大意:给定一个序列.每次选择一个位置,把这个位置之后全部小于等于这个数的数抽出来,排序,再插回去,求每次操作后的逆序对数 首先我们每一次操作 对于这个位置前面的数 因为排序的数与前面的数位置关系不 ...

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

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

  5. 【BZOJ1452】[JSOI2009]Count(树状数组)

    [BZOJ1452][JSOI2009]Count(树状数组) 题面 BZOJ 洛谷 题解 数据范围这么小?不是对于每个颜色开一个什么东西记一下就好了吗. 然而我不会二维树状数组? 不存在的,凭借多年 ...

  6. BZOJ1452 [JSOI2009]Count 【树套树 (树状数组)】

    1452: [JSOI2009]Count Time Limit: 10 Sec  Memory Limit: 64 MB Submit: 2693  Solved: 1574 [Submit][St ...

  7. [bzoj1452][JSOI2009]Count_树状数组

    Count bzoj-1452 JSOI-2009 题目大意:请维护一个平面内的数据结构,支持:单点修改,查询矩形内给定权值出现次数. 注释:$1\le n,m\le 300$,$1\le Q \le ...

  8. 【BZOJ-1452】Count 树状数组 套 树状数组

    1452: [JSOI2009]Count Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1769  Solved: 1059[Submit][Stat ...

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

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

随机推荐

  1. webpack 清理旧打包资源插件

    当我们修改带hash的文件并进行打包时,每打包一次就会生成一个新的文件,而旧的文件并 没有删除.为了解决这种情况,我们可以使用clean-webpack-plugin 在打包之前将文件先清除,之后再打 ...

  2. Python学习day36-并发编程(2)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  3. PostgreSQL DISTINCT ON

    https://stackoverflow.com/questions/3800551/select-first-row-in-each-group-by-group select DISTINCT ...

  4. spring boot 项目添加maven依赖时provided

    spring boot 项目是自带tomcat 的,但是我们有时候是需要把项目打包成war 然后放到独立的tomcat中运行的,这个时候我们就需要将它自带的tomcat给排除开,这时候我们就可以使用& ...

  5. Solr+HBase

  6. /proc/cpuinfo和/proc/meminfo来查看cpu信息与内存信息

    #一般情况下使用root或者oracle用户查都可以. # 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数 --查 ...

  7. 实战课堂 | MongoDB如何使用内存?内存满了怎么破?

    最近接到多个MongoDB内存方面的线上case及社区问题咨询,主要集中在: 为什么我的 MongoDB 使用了 XX GB 内存? 一个机器上部署多个 Mongod 实例/进程,WiredTiger ...

  8. CF1140F - Extending Set of Points

    题意:对于点集S,定义函数F(S)为对S不断扩展到不能扩展时S的点数.一次扩展定义为如果有一个平行于坐标轴的矩形的三个点在S中,则第四个点加入S. 动态在S中加点删点,每次操作完后求F(S)的值. 解 ...

  9. HZOI2019 超级树 dp

    题面:https://www.cnblogs.com/Juve/articles/11207540.html(密码)————————————————>>> 题解: 官方题解: 考虑d ...

  10. vs2013+opencv2410的一些问题

    1.设置microsoft.user时,debug和relaese只能修改一次,相对应的32和64会相应修改,因此可以新建一个属性表,命名为OpenCV2410debug: 2.报错:error LN ...