题目传送门

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

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. .NET控件命名规范

    一.基本数据类型前缀 数据类型    数据类型简写 Array    arr Boolean    bln Byte    byt Char    chr DateTime    dtm Decima ...

  2. 使用nodejs代码在SAP C4C里创建Individual customer

    需求:使用nodejs代码在SAP Cloud for Customer里创建Individual customer实例. 代码: var createAndBind = require('../je ...

  3. 指数循环节&欧拉降幂

    证明:https://www.cnblogs.com/maijing/p/5046628.html 注意使用条件(B的范围) 例题: FZU1759 HDU2837 ZOJ1674 HDU4335

  4. TensorFlow基础(二)实现神经网络

    (1)前向传播算法 神经网络的前向传播算法主要构成部分: 1.神经网络的输入: 2.神经网络的连接结构:神经网络是由神经元(节点)构成的 3.每个神经元中的参数. (2)TensorFlow随机数生成 ...

  5. ZOJ Monthly, January 2019 Little Sub and Isomorphism Sequences 【离线离散化 + set + multiset】

    传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5868 Little Sub and Isomorphism Seque ...

  6. Linux磁盘分区,挂载

    分区基础知识 分区的方式:   1) mbr分区:     1.最多支持四个主分区     2.系统只能安装在主分区     3.扩展分区要占一个主分区     4.MBR最大只支持2TB,但拥有最好 ...

  7. spring bean中构造函数,afterPropertiesSet和init-method的执行顺序

    http://blog.csdn.net/super_ccc/article/details/50728529 1.xml文件 <bean id="aaa" class=&q ...

  8. centos7 yum安装mysql后启动不起来问题

    [root@localhost ~]# systemctl start mysqld       启动失败 Job for mysqld.service failed because the cont ...

  9. iOS之序列化与反序列化

    所谓的序列化和反序列化就是将数据结构或对象和二进制串之间相互转换的过程: 本人的理解是当你于写数据需要本地存储时,即将你的数据写到硬盘上的时候,你就必须对他进行序列化,转换成二进制文件,从而便于在磁盘 ...

  10. 如何在html中插入图片

    HTML内容元素中图片元素 使用img元素:src属性:图片路径. alt属性:图片无法显示的时候使用替代文本,title属性:鼠标悬停时显示文本内容. 在同一张图片上点击不同的位置链接到不同的页面上 ...