【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 ...
随机推荐
- PAT (Advanced Level) 1088. Rational Arithmetic (20)
简单题. 注意:读入的分数可能不是最简的.输出时也需要转换成最简. #include<cstdio> #include<cstring> #include<cmath&g ...
- Spring Boot集成Spring Data Reids和Spring Session实现Session共享(多个不同的应用共用一个Redis实例)
从Redis的Key入手,比如Spring Session在注解@EnableRedisHttpSession上提供了redisNamespace属性,只需要在这里设置不同的值即可,效果应该是这样的: ...
- SUPEROBJECT序列数据集为JSON
// SUPEROBJECT 序列数据集 cxg 2017-1-12// {"data":[{"c1":1,"c2":1}]};// DEL ...
- 【面试 spring】【第七篇】spring的问题
1.spring你熟悉么?两大特色 spring 主要有IOC和AOP两大特色. =========================================================== ...
- [Testing] Config jest to test Javascript Application -- Part 3
Run Jest Watch Mode by default locally with is-ci-cli In CI, we don’t want to start the tests in wat ...
- 电脑技巧 ADSL如何远程盗号
ADSL如何远程盗号 开头语: 本文中揭露了黑客攻击ADSL用户,窃取用户名密码的常见方法,读者请勿将其用于不法用途,并提醒所有与此漏洞相关的用户尽快采取措施进行防范. ADSL作为一种宽带接入方式已 ...
- 创建一个简单的 http 服务器
创建一个简单的 http 服务器 直接在 目录下运行 当前的目录即可是root 目录 默认端口8000 应该可以加参数修改端口号 Python2 python -m SimpleHTTPServer ...
- JavaScript与Java通信
1.WebView中JavaScript调用Android程序中Java: 使用WebView类中的addJavascriptInterface()方法,能够使用它扩展嵌入式浏览器内的DOM(文档对象 ...
- go test test & benchmark
开发程序其中很重要的一点是测试,我们如何保证代码的质量,如何保证每个函数是可运行,运行结果是正确的,又如何保证写出来的代码性能是好的,我们知道单元测试的重点在于发现程序设计或实现的逻辑错误,使问题及早 ...
- MVC Page分页控件
MVCPage帮助类 控制器代码 public ActionResult Article(int? page) { //Session["ArticleClass"] = cont ...