1452: [JSOI2009]Count

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 1769  Solved: 1059
[Submit][Status][Discuss]

Description

Input

Output

Sample Input

Sample Output

1
2

HINT

Source

Solution

忽略标题的说法...撞壁用的....

简单题,裸树状数组套树状数组

颜色数目$c<=100$很小,考虑对于每种颜色单独进行处理

那么对于每个颜色单独开一个二维树状数组维护

另开一个二维数组记录下当前各个位置的颜色

1操作,将原有颜色树状数组中的$(x,y)$点置成0,在新颜色树状数组中置成1,并更新颜色的状态

2操作,区间查询,应用前缀和,进行一下加减即可得到当前子矩阵和

Code

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int read()
{
int x=,f=; char ch=getchar();
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
}
int n,m,q;int zt[][];
struct Treenode
{
int tree[][];
Treenode(){memset(tree,,sizeof(tree));}
int lowbit(int x){return x&-x;}
void change(int x,int y,int del)
{
for (int i=x; i<=n; i+=lowbit(i))
for (int j=y; j<=m; j+=lowbit(j))
tree[i][j]+=del;
}
int query(int x,int y)
{
int ans=;
for (int i=x; i; i-=lowbit(i))
for (int j=y; j; j-=lowbit(j))
ans+=tree[i][j];
return ans;
}
int ask(int x1,int y1,int x2,int y2)
{
return query(x2,y2)-query(x2,y1-)-query(x1-,y2)+query(x1-,y1-);
}
}color[]; int main()
{
n=read(); m=read();
for (int i=; i<=n; i++)
for (int col,j=; j<=m; j++)
col=read(),color[col].change(i,j,),zt[i][j]=col;
q=read();
for (int i=; i<=q; i++)
{
int opt=read(),x1,y1,x2,y2,col;
if (opt==)
{
x1=read(),y1=read(),col=read();
color[zt[x1][y1]].change(x1,y1,-);
zt[x1][y1]=col;
color[col].change(x1,y1,);
continue;
}
x1=read(),x2=read(),y1=read(),y2=read(),col=read();
printf("%d\n",color[col].ask(x1,y1,x2,y2));
}
return ;
}

5分钟不到,看、想、写、1A系列....

最新文章

  1. css选择器中:first-child与:first-of-type的区别
  2. Docker的单主机容器网络
  3. Oracle用户信息查询
  4. Struts输出流向jsp页面写入图片乱码
  5. 20151214 jquery插件代码备份
  6. Hadoop, Python, and NoSQL lead the pack for big data jobs
  7. SQLSERVER 中GO的作用详解
  8. MFC CSplitterWnd的用法
  9. 用XAML做网页!!—页头
  10. maven系列--maven常用命令
  11. hdu 5591 BestCoder Round #65(博弈)
  12. Android开发学习之路--RxAndroid之lambda
  13. centOS连接没问题,使用SecureCRT就不能连接
  14. Java 身份证号码验证
  15. 置顶菜单demo
  16. iOS - App Extension 整体总结
  17. BZOJ5314 [Jsoi2018]潜入行动 【背包类树形dp】
  18. uid
  19. python greenlet背景介绍与实现机制
  20. 【SpringMVC学习06】SpringMVC中的数据校验

热门文章

  1. UESTC 31 饭卡(Card) --背包问题
  2. java 21 - 10 文本文件和集合之间互相存储数据
  3. 关于软件测试人员能力模型的建立(from知乎)
  4. ArcGis 统计方法
  5. 20Mybatis_订单商品数据模型_一对一查询——resultType和resultMap两种方式以及两种方式的总结
  6. R语言利器之ddply和aggregate
  7. [tools]tcp/udp连通性测试
  8. svn命令行修改已提交的版本备注
  9. 未能进入中断模式,原因如下:源文件“XXXXXX”不属于正在调试的项目。
  10. OpenGL 4.3配置教程