【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 ...
随机推荐
- codeforces 1041 e 构造
Codeforces 1041 E 构造题. 给出一种操作,对于一棵树,去掉它的一条边.那么这颗树被分成两个部分,两个部分的分别的最大值就是这次操作的答案. 现在给出一棵树所有操作的结果,问能不能构造 ...
- electron 自定义菜单
快捷键:http://electronjs.org/docs/api/accelerator
- Mysql 性能优化20个原则(2)
5. 在Join表的时候使用相当类型的例,并将其索引 如果你的应用程序有很多 JOIN 查询,你应该确认两个表中Join的字段是被建过索引的.这样,MySQL内部会启动为你优化Join的SQL语句的机 ...
- python 工具 FFT变换
import numpy as npimport pylabwave_data =np.fromfile("C:\\Users\\Administrator\\Desktop\\bins\\ ...
- hadoop-mapreduce中reducetask执行分析
ReduceTask的执行 Reduce处理程序中须要运行三个类型的处理, 1.copy,从各map中copy数据过来 2.sort,对数据进行排序操作. 3.reduce,运行业务逻辑的处理. Re ...
- Type cannot use 'try' with exceptions disabled
cannot use ‘throw’ with exceptions disabled 在为 DragonBonesCPP/refactoring 的 cocos2d-x-3.2 demo 增加 An ...
- ok6410[000] ubuntu1604_64bit下安装wps
虽说Ubuntu下有自动的office工具,不过使用上体验很差.而国内最好的office软件也就是金山的wps. ------------------------------------------- ...
- C#Unicode和Utf-8
Unicode(统一码.万国码.单一码)是一种在计算机上使用的字符编码.Unicode 是为了解决传统的字符编码方案的局限而产生的,它为每种语言中的每个字符设定了统一并且唯一的二进制编码,以满足跨语言 ...
- Arcgis Engine(ae)接口详解(1):featureClass
//IFeatureClass 来源请自行解决 IFeatureClass featureClass = null; //获取featureClass的各种名称 //PS:featureClass可以 ...
- WM_GETMINMAXINFO的作用 .
如果想要实现窗口全屏,并且还有状态栏,会出现问题,那就是OnGetMinMaxInfo函数的作用.你可以试一下,如果把这个函数去掉,则当你按下工具栏中的全屏显示按钮时,框架视图确实变大了,但没有想象的 ...