题目传送门

二维树状数组,对于每个颜色开一个树状数组,用容斥求解。

code:

#include <cstdio>
using namespace std; int read()
{
char c;while(c=getchar(),c<''||c>'');
int x=c-'';while(c=getchar(),c>=''&&c<='')x=x*+c-'';
return x;
} int N,M,tr[][][],a[][]; void add(int x,int y,int c,int p)
{
for(int i=x;i<=N;i+=i&-i)
for(int j=y;j<=M;j+=j&-j)
tr[c][i][j]+=p;
return ;
} int get(int x,int y,int c)
{
int ans=;
for(int i=x;i;i-=i&-i)
for(int j=y;j;j-=j&-j)
ans+=tr[c][i][j];
return ans;
} int main()
{
N=read(),M=read();
for(int i=;i<=N;i++)
for(int j=;j<=M;j++)
add(i,j,a[i][j]=read(),);
int Q=read();
while(Q--){
int o=read();
if(o==){
int x=read(),y=read(),c=read();
add(x,y,a[x][y],-);
add(x,y,a[x][y]=c,);
}
else{
int x=read(),fx=read(),y=read(),fy=read(),c=read();
printf("%d\n",get(fx,fy,c)-get(x-,fy,c)-get(fx,y-,c)+get(x-,y-,c));
}
}
}

BZOJ1452_Count_KEY的更多相关文章

随机推荐

  1. CoreAnimation confusion: CATransaction vs CATransition vs CAAnimationGroup?

    http://stackoverflow.com/questions/14042755/coreanimation-confusion-catransaction-vs-catransition-vs ...

  2. 五·管理mysql

    在上一篇文章中 四·安装mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz(基于Centos7源码安装) 已经安装好了mysql,也正常启动了.本篇文章主要内容是管理m ...

  3. 「CF375D Tree and Queries」

    题目 \(dsu\ on\ tree\)的板子题了 \(dsu\ on\ tree\)本质上一种优秀通过轻重链剖分优化到\(O(nlogn)\)的暴力 一般用来解决没有修改的允许离线的子树查询问题 首 ...

  4. 解决 git pull 报错 fatal: refusing to merge unrelated histories

    我在Github新建一个仓库,写了License,然后把本地一个写了很久仓库上传. 先pull,因为两个仓库不同,发现refusing to merge unrelated histories,无法p ...

  5. 单表60亿记录等大数据场景的MySQL优化和运维之道 | 高可用架构

    015-08-09 杨尚刚 高可用架构 此文是根据杨尚刚在[QCON高可用架构群]中,针对MySQL在单表海量记录等场景下,业界广泛关注的MySQL问题的经验分享整理而成,转发请注明出处. 杨尚刚,美 ...

  6. Qgis 里的Python脚本介绍

    QGIS 入门演示之<用 QGIS 画矢量交通路线图> 脚本编程之准备知识<Python 教程> QGIS API QGIS插件库 运行QGIS脚本,对于桌面应用来讲有4种方式 ...

  7. Anaconda常用命令

    conda版本: conda --version 环境信息: 激活环境后,conda info 查看环境已安装包: conda list 新建环境: conda create -n {NAME} [ ...

  8. 一个jquery ajax例子

    上次搞了个jquery的AutoComplete效果,感觉很久没写jquery了,趁热打铁,再找点东西练练手.这不,看了一下jquery手册,顺便写了一个小例子,源码我直接贴上来了.   1.新建一个 ...

  9. DU1525 Euclid's Game 博弈

    HDU1525 Euclid's Game 博弈 题意 给定两个数字 a, b. 每次只能用 较大的值 减去 较小的值的倍数, 两个人轮流进行操作, 第一个得到 0 的胜利. 分析 对于 a == b ...

  10. Race UVA - 12034(dp+打表)

    Disky and Sooma, two of the biggest mega minds of Bangladesh went to a far country. They ate, coded ...