1452: [JSOI2009]Count

Time Limit: 10 Sec  Memory Limit: 64 MB

Submit: 2693  Solved: 1574

[Submit][Status][Discuss]

Description

Input

Output

Sample Input




Sample Output

1

2

HINT

开心~自己写出了树套树【蒟蒻的欢愉】

颜色很少,区间也很小,对每种颜色开一个二维树状数组就好了

第一维表示x,对应x行的第二维树状数组

复杂度O(Qlog^2n)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = head[u]; k != -1; k = edge[k].next)
#define lbt(x) (x & -x)
using namespace std;
const int maxn = 305,maxm = 105,INF = 1000000000;
inline int RD(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57) {if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57) {out = (out << 1) + (out << 3) + c - '0'; c = getchar();}
return out * flag;
}
int A[maxm][maxn][maxn],s[maxn][maxn],n,m,Q;
inline void add(int c,int p,int u,int v){while (u <= m) A[c][p][u] += v,u += lbt(u);}
inline int query(int c,int p,int u){int ans = 0; while (u) ans += A[c][p][u],u -= lbt(u); return ans;}
inline int sum(int c,int p,int l,int r){return query(c,p,r) - query(c,p,l - 1);}
inline void modify(int c,int x,int y,int v){while (x <= n) add(c,x,y,v),x += lbt(x);}
inline int Query(int c,int x,int l,int r){int ans = 0; while (x) ans += sum(c,x,l,r),x -= lbt(x); return ans;}
inline int Sum(int c,int xl,int xr,int yl,int yr){return Query(c,xr,yl,yr) - Query(c,xl - 1,yl,yr);}
int main(){
n = RD(); m = RD(); int x,y,x1,y1,c,cmd;
REP(i,n) REP(j,m) s[i][j] = RD(),modify(s[i][j],i,j,1);
Q = RD();
while (Q--){
cmd = RD();
if (cmd & 1){
x = RD(); y = RD(); c = RD();
modify(s[x][y],x,y,-1); modify(c,x,y,1); s[x][y] = c;
}else {
x = RD(); x1 = RD(); y = RD(); y1 = RD(); c = RD();
printf("%d\n",Sum(c,x,x1,y,y1));
}
}
return 0;
}

BZOJ1452 [JSOI2009]Count 【树套树 (树状数组)】的更多相关文章

  1. [BZOJ 1901] Dynamic Rankings 【树状数组套线段树 || 线段树套线段树】

    题目链接:BZOJ - 1901 题目分析 树状数组套线段树或线段树套线段树都可以解决这道题. 第一层是区间,第二层是权值. 空间复杂度和时间复杂度均为 O(n log^2 n). 线段树比树状数组麻 ...

  2. ZJOI 2017 树状数组(线段树套线段树)

    题意 http://uoj.ac/problem/291 思路 不难发现,九条カレン醬所写的树状数组,在查询区间 \([1,r]\) 的时候,其实在查询后缀 \([r,n]\) :在查询 \([l,r ...

  3. 【bzoj4785】[Zjoi2017]树状数组 线段树套线段树

    题目描述 漆黑的晚上,九条可怜躺在床上辗转反侧.难以入眠的她想起了若干年前她的一次悲惨的OI 比赛经历.那是一道基础的树状数组题.给出一个长度为 n 的数组 A,初始值都为 0,接下来进行 m 次操作 ...

  4. dfs序+主席树 或者 树链剖分+主席树(没写) 或者 线段树套线段树 或者 线段树套splay 或者 线段树套树状数组 bzoj 4448

    4448: [Scoi2015]情报传递 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 588  Solved: 308[Submit][Status ...

  5. bzoj 3196 Tyvj 1730 二逼平衡树(线段树套名次树)

    3196: Tyvj 1730 二逼平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1807  Solved: 772[Submit][Stat ...

  6. BZOJ4317Atm的树&BZOJ2051A Problem For Fun&BZOJ2117[2010国家集训队]Crash的旅游计划——二分答案+动态点分治(点分树套线段树/点分树+vector)

    题目描述 Atm有一段时间在虐qtree的题目,于是,他满脑子都是tree,tree,tree…… 于是,一天晚上他梦到自己被关在了一个有根树中,每条路径都有边权,一个神秘的声音告诉他,每个点到其他的 ...

  7. hdu-4819-线段树套线段树

    http://acm.hdu.edu.cn/showproblem.php?pid=4819 给出一个N*N的矩阵,每次询问一个m*m的子矩阵里的floor((maxv+minv)/2)并把中间的元素 ...

  8. 【vijos】1750 建房子(线段树套线段树+前缀和)

    https://vijos.org/p/1750 是不是我想复杂了.... 自己yy了个二维线段树,然后愉快的敲打. 但是wa了两法.......sad 原因是在处理第二维的更新出现了个小问题,sad ...

  9. 【题解】BZOJ3489 A Hard RMQ problem(主席树套主席树)

    [题解]A simple RMQ problem 占坑,免得咕咕咕了,争取在2h内写出代码 upd:由于博主太菜而且硬是要用指针写两个主席树,所以延后2hQAQ upd:由于博主太菜而且太懒所以他决定 ...

  10. [TJOI2017][bzoj4889] 不勤劳的图书管理员 [线段树套线段树]

    题面 传送门 思路 考虑两本书的位置交换对答案的贡献: (为了方便描述,用"左边那本"和"右边那本"称呼两本我们要交换的书,"中间那本"是我 ...

随机推荐

  1. ThinkPHP创建应用

    新建一个文件 引入ThinkPHP文件

  2. ZooKeeper(3)-内部原理

    一. 节点类型 二. Stat结构体 1)czxid-创建节点的事务zxid 每次修改ZooKeeper状态都会收到一个zxid形式的时间戳,也就是ZooKeeper事务ID. 事务ID是ZooKee ...

  3. Hadoop(20)-MapReduce框架原理-OutputFormat

    1.outputFormat接口实现类 2.自定义outputFormat 步骤: 1). 定义一个类继承FileOutputFormat 2). 定义一个类继承RecordWrite,重写write ...

  4. C语言运算符优先级和结合性

    运算符优先级和结合性 优先级                                       运算符 结合性                                         ...

  5. Spring配置文件一直报错的根源所在

    跳坑后的感悟总结 Spring在配置文件中经常会报XML错误,以下是几种常见的解决办法 方式一:打开eclipse-->Project-->Clean ;清除一下 方式二:查看xml配置文 ...

  6. innodb_index_stats

    mysql> select * from mysql.innodb_index_stats WHERE database_name='test' and table_name='recordsI ...

  7. unresolved symbol @__security_check_cookie 解决方法

    ntstrsafe.lib(output.obj) : error LNK2019: unresolved external symbol @__security_check_cookie@4 ref ...

  8. mysql8.0.14 安装

    1.下载 地址:https://dev.mysql.com/downloads/mysql/ 找到zip压缩文件. 2.配置环境变量 把解压后的路径配置到环境变量中 3.安装 在解压后的文件夹中新建m ...

  9. 开发react的一些记录

    1.keyboard事件返回的对象SyntheticKeyboardEvent全部是null 解决方法:SyntheticKeyboardEvent的type,which,timeStamp可以得到你 ...

  10. CSP201509-1:数组分段

    引言:CSP(http://www.cspro.org/lead/application/ccf/login.jsp)是由中国计算机学会(CCF)发起的“计算机职业资格认证”考试,针对计算机软件开发. ...