BZOJ 1452 Count
长知识啦。。二维BIT。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,q,t[][][],map[][];
int a,b,c,d,e,f;
int lowbit(int x)
{
return x&(-x);
}
void update(int x,int y,int c,int val)
{
for (int i=x;i<=n;i+=lowbit(i))
for (int j=y;j<=m;j+=lowbit(j))
t[c][i][j]+=val;
}
int ask(int x,int y,int c)
{
int tmp=;
for (int i=x;i>=;i-=lowbit(i))
for (int j=y;j>=;j-=lowbit(j))
tmp+=t[c][i][j];
return tmp;
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
{
scanf("%d",&map[i][j]);
update(i,j,map[i][j],);
}
scanf("%d",&q);
for (int i=;i<=q;i++)
{
scanf("%d",&a);
if (a==)
{
scanf("%d%d%d",&b,&c,&d);
update(b,c,map[b][c],-);
update(b,c,d,);
map[b][c]=d;
}
else
{
scanf("%d%d%d%d%d",&b,&c,&d,&e,&f);
int q1=,q2=,q3=,q4=;
q1=ask(c,e,f);
if (b>=) q2=ask(b-,e,f);
if (d>=) q3=ask(c,d-,f);
if ((b>=) && (d>=)) q4=ask(b-,d-,f);
printf("%d\n",q1-q2-q3+q4);
}
}
return ;
}
BZOJ 1452 Count的更多相关文章
- BZOJ 1452 Count(二维树状数组)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1452 题意:给出一个数字矩阵(矩阵中任何时候的数字均为[1,100]),两种操作:(1) ...
- BZOJ 1452 Count(二维树状数组)
大水题. 建立100个二维树状数组,总复杂度就是O(qlognlogm). # include <cstdio> # include <cstring> # include & ...
- BZOJ 1452 Count 【模板】二维树状数组
对每种颜色开一个二维树状数组 #include<cstdio> #include<algorithm> using namespace std; ; ][maxn][maxn] ...
- BZOJ 1452: [JSOI2009]Count 二维树状数组
1452: [JSOI2009]Count Description Input Output Sample Input Sample Output 1 2 HINT Source 题解:设定C[101 ...
- BZOJ 1452: [JSOI2009]Count(二维BIT)
为每一个权值开一个二维树状数组. ------------------------------------------------------------------------- #include& ...
- 二维树状数组 BZOJ 1452 [JSOI2009]Count
题目链接 裸二维树状数组 #include <bits/stdc++.h> const int N = 305; struct BIT_2D { int c[105][N][N], n, ...
- bzoj 1452: [JSOI2009]Count (二维树状数组)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1452 思路: 对每个颜色开一个二维树状数组维护就好了 实现代码: #include<b ...
- BZOJ 1452:[JSOI2009]Count(二维树状数组)
[JSOI2009]Count 描述 输入 输出 1 2 分析: 裸二维bit,对每个颜色建一颗bit. program count; var bit:..,..,..]of longint; a:. ...
- BZOJ 1452 [JSOI2009] Count
这道题好像有点简单的样子... absi找题目好厉害啊...确实是一道比较裸的2dBIT啊. 水掉吧. 附:2dBIT怎么做: 2dBIT就是BIT套BIT啦. 所以修改loop(x+=lowbit( ...
随机推荐
- cf 383 D
D. Antimatter time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- JavaScript文件应该放在网页的什么位置
JavaScript文件应该放在网页的什么位置 http://www.lihuai.net/qianduan/js/352.html 在<良好的JavaScript编程习惯>系列教程的第三 ...
- [C++]不能被继承的类
前面讲到,派生类的构造函数和析构函数会自动调用基类的构造函数和析构函数,那么要让一个类不能被继承,那么就将它的构造函数和析构函数私有函数(派生类可以访问保护函数).那么怎样才能得到该类的实例呢? 这倒 ...
- 被 Windows 10 SDK 坑了
抓包抓到的配置文件与完整版的VS一致,虽然显示出来的只有 Windows 10 通用工具,我还以为是只更新这些(因为列出来的几个,我确实之前没装),就愉快地点了安装,结果……新建项目时,发现 Wind ...
- UVA 11609 Teams 组合数学+快速幂
In a galaxy far far away there is an ancient game played among the planets. The specialty of the gam ...
- Newtonsoft.Json.dll
代码 using System; DoNet2.0 需要借助于Newtonsoft.Json.dll using System.IO; using System.Text; using Newtons ...
- UITableViewCell的重用机制原理
UITableViewCell的重用机制原理 来自http://blog.csdn.net/omegayy/article/details/7356823 ====================== ...
- iOS开发--自动布局
距离左边的: 距离顶部的: 距离右边的: 距离底部的:
- 图解TCP/IP读书笔记(三)
第三章.数据链路 数据链路层是计算机网络最基本的内容. 数据链路层的协议定义了通过通信媒介互连的设备之间传输的规范. 一.数据链路相关技术 1.MAC地址 关于MAC地址的几个要点: ①MAC地址长度 ...
- windows xp 无法连接wpa无线网络
其实以前一直是可以的,不知为什么前几天忽然就不能加入原有的无线网了.我的无线网是WPA加密的,采用DHCP分配IP(但针对特定MAC地址分配静态IP). 在网上找了许久,有的网友认为应该把无线网卡(那 ...