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. 原生ajax封装及用法

    /* 封装ajax函数 * @param {string}opt.type http连接的方式,包括POST和GET两种方式 * @param {string}opt.url 发送请求的url * @ ...

  2. work-shineyoo:杂项1906

    ylbtech-work-shineyoo:杂项1906 1.返回顶部 1. 1.1 SMS (手机的)短信服务.Short Message Service. 1.2 VOD 视频点播.Video o ...

  3. System.Web.Mvc.RedirectResult.cs

    ylbtech-System.Web.Mvc.RedirectResult.cs 1.程序集 System.Web.Mvc, Version=5.2.3.0, Culture=neutral, Pub ...

  4. MyBatis注解开发-@Insert和@InsertProvider(转)

    @Insert和@InsertProvider都是用来在实体类的Mapper类里注解保存方法的SQL语句.不同的是,@Insert是直接配置SQL语句,而@InsertProvider则是通过SQL工 ...

  5. Image 转换成 Icon

    /// <summary> /// Converts an image into an icon. /// </summary> /// <param name=&quo ...

  6. CAS(客户端)程序获取安全证书

    以下是获取安全证书的一种方法,通过以下程序获取安全证书: import java.io.BufferedReader; import java.io.File; import java.io.File ...

  7. PostgreSQL DISTINCT ON

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

  8. Redis集群搭建详细过程整理备忘

    三.安装配置 1.环境 使用2台centos服务器,每台机器上部署3个实例,集群为三个主节点与三个从节点: 192.168.5.144:6380 192.168.5.144:6381 192.168. ...

  9. git 命令行(一)-版本回退

    1. 版本回退 在实际工作中,我们脑子里怎么可能记得一个几千行的文件每次都改了什么内容,不然要版本控制系统干什么.版本控制系统肯定有某个命令可以告诉我们历史记录,在Git中,我们用 git log 命 ...

  10. light oj 1068 数位dp

    #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> ...