BZOJ1452 [JSOI2009]Count [2017年4月计划 树状数组02]
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
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]的更多相关文章
- 【BZOJ3333】排队计划 树状数组+线段树
[BZOJ3333]排队计划 Description Input Output Sample Input 6 2 160 163 164 161 167 160 2 3 Sample Output 6 ...
- 洛谷P2982 [USACO10FEB]慢下来Slowing down [2017年四月计划 树状数组01]
P2982 [USACO10FEB]慢下来Slowing down 题目描述 Every day each of Farmer John's N (1 <= N <= 100,000) c ...
- BZOJ 3333 排队计划 树状数组+线段树
题目大意:给定一个序列.每次选择一个位置,把这个位置之后全部小于等于这个数的数抽出来,排序,再插回去,求每次操作后的逆序对数 首先我们每一次操作 对于这个位置前面的数 因为排序的数与前面的数位置关系不 ...
- BZOJ 1452 Count 【模板】二维树状数组
对每种颜色开一个二维树状数组 #include<cstdio> #include<algorithm> using namespace std; ; ][maxn][maxn] ...
- 【BZOJ1452】[JSOI2009]Count(树状数组)
[BZOJ1452][JSOI2009]Count(树状数组) 题面 BZOJ 洛谷 题解 数据范围这么小?不是对于每个颜色开一个什么东西记一下就好了吗. 然而我不会二维树状数组? 不存在的,凭借多年 ...
- BZOJ1452 [JSOI2009]Count 【树套树 (树状数组)】
1452: [JSOI2009]Count Time Limit: 10 Sec Memory Limit: 64 MB Submit: 2693 Solved: 1574 [Submit][St ...
- [bzoj1452][JSOI2009]Count_树状数组
Count bzoj-1452 JSOI-2009 题目大意:请维护一个平面内的数据结构,支持:单点修改,查询矩形内给定权值出现次数. 注释:$1\le n,m\le 300$,$1\le Q \le ...
- 【BZOJ-1452】Count 树状数组 套 树状数组
1452: [JSOI2009]Count Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1769 Solved: 1059[Submit][Stat ...
- BZOJ 1452: [JSOI2009]Count 二维树状数组
1452: [JSOI2009]Count Description Input Output Sample Input Sample Output 1 2 HINT Source 题解:设定C[101 ...
随机推荐
- 正则获取html标签字符串中图片地址
html标签字符串: var htmlStr = "<div class='testClass'><img=http://www.chinanews.com/part/ho ...
- memcache课程---4、php+memcache如何让用户跨域登录
memcache课程---4.php+memcache如何让用户跨域登录 一.总结 一句话总结: 让所有服务器共用一台memcache缓存,即可达到跨域的目的 1.session跨域:修改php配置文 ...
- Spring MVC(十)--通过表单序列化传递参数
通过表单序列化传递参数就是将表单数据转化成字符串传递到后台,序列化之后参数请求变成这种模式param1=value1&¶m2=value2,下面用代码实现. 1.创建表单 &l ...
- Struts2接受请求参数三种常用方法
一 接受请求参数主要有三种:属性驱动 对象驱动 模型驱动<model Driven> 方式1:在Action中接收请求参数不需要使用request对象,在Action中定义与请求参数相同名 ...
- vue使用远程在线更新代码
一.main.js import Vue from 'vue' import App from './App' import router from './router' import Vuex fr ...
- MYSQL错误代码和消息
服务器错误信息来自下述源文件: · 错误消息信息列在share/errmsg.txt文件中.“%d”和“%s”分别代表编号和字符串,显示时,它们将被消息值取代. · 错 ...
- [Swoole系列入门教程 5] UDP协议和demo
• 客户端服务端没有任何联系 • 指定地址跟端口,不关心消息是否发送成功 • 心跳检测不能影响到客户端• udp建立长连接
- Innodb_buffer_pool_read
> show status like 'Innodb_buffer_pool_read_%'; +---------------------------------------+-------- ...
- 19-10-18-Night-U
话说T3: 一句话题意……见过这个嘛…… 于是:$\sum \limits_{i!=j} \binom{a_i+b_i+a_j+b_j}{a_i+a_j}$ ------------前言结束----- ...
- dubbo入门学习(五)-----dubbo的高可用
zookeeper宕机与dubbo直连 现象 zookeeper注册中心宕机,还可以消费dubbo暴露的服务. 原因 健壮性 l 监控中心宕掉不影响使用,只是丢失部分采样数据 l 数据库宕掉后,注册中 ...