【JSOI 2009】 Count
【题目链接】
【算法】
二维树状数组
【代码】
#include<bits/stdc++.h>
using namespace std;
#define MAXN 300
#define MAXC 100 int N,M,Q,i,j,opt,x,y,xa,ya,xb,yb,c;
int a[MAXN+][MAXN+]; template <typename T> inline void read(T &x) {
int f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
} template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x%+'');
} template <typename T> inline void writeln(T x) {
write(x);
puts("");
} struct BinaryIndexedTree {
int bit[MAXC+][MAXN+][MAXN+];
int lowbit(int x) { return x & (-x); }
inline void modify(int c,int x,int y,int val) {
int i,j;
for (i = x; i <= N; i += lowbit(i)) {
for (j = y; j <= M; j += lowbit(j)) {
bit[c][i][j] += val;
}
}
}
inline int query(int c,int x,int y) {
int i,j,ret=;
for (i = x; i >= ; i -= lowbit(i)) {
for (j = y; j >= ; j -= lowbit(j)) {
ret += bit[c][i][j];
}
}
return ret;
}
inline int query(int c,int xa,int xb,int ya,int yb) {
return query(c,xb,yb) - query(c,xb,ya-) - query(c,xa-,yb) + query(c,xa-,ya-);
}
} BIT; int main() { read(N); read(M);
for (i = ; i <= N; i++) {
for (j = ; j <= M; j++) {
read(a[i][j]);
BIT.modify(a[i][j],i,j,);
}
}
read(Q);
while (Q--) {
read(opt);
if (opt == ) {
read(x); read(y); read(c);
BIT.modify(a[x][y],x,y,-);
BIT.modify(c,x,y,);
a[x][y] = c;
} else {
read(xa); read(xb); read(ya); read(yb); read(c);
writeln(BIT.query(c,xa,xb,ya,yb));
}
} return ; }
【JSOI 2009】 Count的更多相关文章
- 【POJ 2777】 Count Color(线段树区间更新与查询)
[POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4094 ...
- 【SCOI 2009】 Windy数
[题目链接] 点击打开链接 [算法] 数位DP,注意处理前导零的情况 [代码] #include<bits/stdc++.h> using namespace std; #define M ...
- 【JSOI 2014】序列维护
[题目链接] 点击打开链接 [算法] 线段树 注意标记下传 [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 5 ...
- 【JSOI 2007】建筑抢修
[题目链接] 点击打开链接 [算法] 将T2从小到大排序,当决策当前建筑修或不修时,若当前花费时间 + T1 <= T2,则修,否则判断T1是否小于之前修的 T1最大的建筑,若小于,则修,我们可 ...
- 【JSOI 2008】 最大数
[题目链接] 点击打开链接 [算法] 很明显,我们可以用线段树解决此题 只需维护区间最值就可以了 [代码] #include<bits/stdc++.h> using namespace ...
- 【JSOI 2007】祖玛
[题目链接] 点击打开链接 [算法] f[i][j]表示第i段到第j段,最少需要多少次全部消除 那么,当color[i] = color[j]时 : 若s[i] + s[j] > 2,根据题目中 ...
- 【JSOI 2008】 最小生成树计数
[题目链接] 点击打开链接 [算法] 笔者做这题参考了这篇博客 : https://blog.sengxian.com/solutions/bzoj-1016 推荐阅读 首先,我们需要知道三个定理 : ...
- 【JSOI 2011】 分特产
[题目链接] 点击打开链接 [算法] 考虑求每个人可以不分的方案 那么,对于每件物品,我们把它分成n份,每一份对应分给每一个人,有C(a[i]+n-1,m-1)种方案,而总方案数就是每种 物品方案数的 ...
- 【POJ 2777】 Count Color
[题目链接] http://poj.org/problem?id=2777 [算法] 线段树 [代码] #include <algorithm> #include <bitset&g ...
随机推荐
- 非旋转Treap:用运行时间换调试时间的有效手段
非旋转Treap:用运行时间换调试时间的有效手段 Hello大家好,我们今天来聊一聊非旋转Treap. 相信各位或多或少都做过些序列上的问题.如果水题我们考虑暴力:不强制在线我们可能用过莫队和待修 ...
- 中国剩余定理 & 欧拉函数 & 莫比乌斯反演 & 狄利克雷卷积 & 杜教筛
ssplaysecond的博客(请使用VPN访问): 中国剩余定理: https://ssplaysecond.blogspot.jp/2017/04/blog-post_6.html 欧拉函数: h ...
- Maven配置将war包部署到Tomcat(tomcat7-maven-plugin)
Tomcat7/8: 提示:经过测试Tomcat7的配置和插件在Tomcat8中能正常运行 tomcat7-maven-plugin官方帮助文档:http://tomcat.apache.org/ma ...
- Opengl配置
Opengl配置说明: 本配置文档针对windows64位操作系统,配置vs2008项目工程 1.下载OpenGL的glut类库:http://www.opengl.org/resources/lib ...
- PHP实现INT型,SHORT型,STRING转换成BYTE数组
实现PHP实现INT型,SHORT型,STRING转换成BYTE数组的转化: class Bytes { public static function integerToBytes($val) { $ ...
- Obj-C, library with ARC code and warning - Method possibly missing a [super dealloc] call?
1 down vote favorite I'm adding the MKStoreKit to my app and I'm getting a warning, Method possibly ...
- 【IntelliJ IDEA】2017.3.4版本永久破解
[本版本软件包和破解jar在网盘上有 我的网盘--技术--idea破解所需要的] 1.idea官网下载 历史版本 选择2017.3.4版本下载 https://www.jetbrains.com ...
- Mecanim动画编辑器 - 加入动画层实现并行动作
1.创建新的状态层 a) 通过下图的1button创建一个新的层 b) 通过下图2属性设置图层的权重.假设为0,则该图层的状态不会影响到总的状态机 c) Mask是设置动画的Avatar的关联节 ...
- Mysql学习之十二:JDBC连接数据库之DriverManager方法
JDBC连接数据库 •创建一个以JDBC连接数据库的程序,包括7个步骤: 1.载入JDBC驱动程序: 在连接数据库之前.首先要载入想要连接的数据库的驱动到JVM(Java虚拟机). 这通过java.l ...
- 分享一个ci 框架下取不到cookie的问题
由于项目中用到了网银支付,在360极速浏览器和其它双核浏览器中,当跳转到付款时他们会强制的把浏览器的模式改为兼容模式,这样一来在极速模式下的cookie在兼容模式下取不到,因为浏览器切换模式的时候us ...