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 ...
随机推荐
- C# FTP上传下载(支持断点续传)
<pre class="csharp" name="code"><pre class="csharp" name=&quo ...
- PAT甲级——A1090 Highest Price in Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- linux操作mysql命令快速手记 — 让手指跟上思考的速度(二)
这一篇是<mysql内建命令快速手记>的姐妹篇,废话不再赘述,直接上干货,跟老铁慢慢品 1.mysql -hlocalhost -uroot -proot,-h,-u,-p分别代表ip,u ...
- C#获取MP3,WMA信息
用于获取MP3内部信息,包括歌曲名,歌手名等…… namespace FileBatchRemaer.domain { /// <summary> /// Mp3信息结构 /// < ...
- 从一个prismWpfMVVM的例子中学到的
整个程序如下,从博客园一个作者看到的例子,但是对这个例子做了点修改.我觉得这个更符合MVVM模式.这个用到了prism框架,在项目中要引用Microsoft.Practices.Prism.dll 按 ...
- 10-2-点击生成10个div
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- STL与泛型编程-学习2-GeekBand
9, 容器 Deque 双向队列 和vector类似, 新增加: push_front 在头部插入一个元素 pop_front 在头部弹出一个元素 Deque和vector内存管理不同: 大块分配内存 ...
- 推荐5款超实用的.NET性能分析工具
虽然.NET框架号称永远不会发生内存泄漏,原因是引入了内存回收机制.但在实际应用中,往往我们分配了对象但没有释放指向该对象的引用,导致对象永远无法释放.最常见的情况就是给对象添加了事件处理函数,但当不 ...
- light oj 1071 dp(吃金币升级版)
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> ...
- 做网站-mysql表字段设计
https://mp.weixin.qq.com/s/HhdbmQqKmiw9IVnnL0Zyag VARCHAR与CHAR如何选择 使用VARCHAR理由 字段不经常更新 字段比较长,且长度不均(比 ...