1452: [JSOI2009]Count - BZOJ

Description


Input


Output


Sample
Input

Sample Output

1

2
HINT

一开始还想什么离线做,其实不用,空间足够,我们直接开100个二维树状数组,然后就行了

但是如果c范围很大就离线做好一些

 1 type
2 tree=array[0..300,0..300]of longint;
3 var
4 s:array[0..100]of tree;
5 a:array[0..300,0..300]of longint;
6 n,m,q:longint;
7
8 procedure add(var c:tree;x,y,w:longint);
9 var
10 i:longint;
11 begin
12 while x<=n do
13 begin
14 i:=y;
15 while i<=m do
16 begin
17 inc(c[x,i],w);
18 i:=i+(i and (-i));
19 end;
20 x:=x+(x and (-x));
21 end;
22 end;
23
24 function sum(var c:tree;x,y:longint):longint;
25 var
26 i:longint;
27 begin
28 sum:=0;
29 while x>0 do
30 begin
31 i:=y;
32 while i>0 do
33 begin
34 inc(sum,c[x,i]);
35 i:=i-(i and (-i));
36 end;
37 x:=x-(x and (-x));
38 end;
39 end;
40
41 procedure main;
42 var
43 i,j,x1,y1,x2,y2,c:longint;
44 begin
45 read(n,m);
46 for i:=1 to n do
47 for j:=1 to m do
48 begin
49 read(a[i,j]);
50 add(s[a[i,j]],i,j,1);
51 end;
52 read(q);
53 for i:=1 to q do
54 begin
55 read(j);
56 if j=1 then
57 begin
58 read(x1,y1,c);
59 add(s[a[x1,y1]],x1,y1,-1);
60 a[x1,y1]:=c;
61 add(s[c],x1,y1,1);
62 end
63 else
64 begin
65 read(x1,x2,y1,y2,c);
66 writeln(sum(s[c],x2,y2)+sum(s[c],x1-1,y1-1)-sum(s[c],x1-1,y2)-sum(s[c],x2,y1-1));
67 end;
68 end;
69 end;
70
71 begin
72 main;
73 end.

1452: [JSOI2009]Count - BZOJ,布布扣,bubuko.com

时间: 2024-12-27 23:21:19

1452: [JSOI2009]Count - BZOJ的相关文章

BZOJ 1452: [JSOI2009]Count (二维树状数组)

Description Input Output Sample Input Sample Output 1 2 HINT 二维树状数组的简单应用,c数组的第一维坐标相当于哈希.如果是修改操作,修改前 将当前的值的个数以及祖先都减1, 修改后将个数加1. #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <set> #include

BZOJ 1452: [JSOI2009]Count 二维树状数组

1452: [JSOI2009]Count Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/problem.php?id=1452 Description Input Output Sample Input Sample Output 1 2 HINT 题意 题解: 裸的二维树状数组 代码: //qscqesze #include <cstdio> #include <cmath&g

1452: [JSOI2009]Count

1452: [JSOI2009]Count Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 2083  Solved: 1228[Submit][Status][Discuss] Description Input Output Sample Input Sample Output 1 2 HINT 思路:二维树状数组: 将数组开三维的然后,每一维维护一个值,然后直接二维树状数组维护即可: 1 #include<stdio.h> 2 #includ

【BZOJ】1452: [JSOI2009]Count

http://www.lydsy.com/JudgeOnline/problem.php?id=1452 题意:n×m的矩阵上每个点有个颜色,现在有q个操作:1 x y c 将点(x,y)的颜色改为c:2 x1 x2 y1 y2 c 询问矩阵x1y1-x2y2颜色为c的格子数目 #include <bits/stdc++.h> using namespace std; const int N=301; int n, m; int S[101][N][N], col[N][N]; void up

【BZOJ】1452: [JSOI2009]Count 树状数组

Description Input Output Sample Input Sample Output 1 2 HINT 题解: 二维的树状数组啊+一维的颜色状态,然后直接做就好……实际上比照一维的树状数组就是多了一个for循环,然后查询操作的时候就相当于查询某一矩阵的大小,树状数组起到一个类似前缀和的作用.   1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <

BZOJ 1452 [JSOI2009] Count

这道题好像有点简单的样子... absi找题目好厉害啊...确实是一道比较裸的2dBIT啊. 水掉吧. 附:2dBIT怎么做: 2dBIT就是BIT套BIT啦. 所以修改loop(x+=lowbit(x)){loop(y+=lowbit(y)){}} 查询loop(x-=lowbit(x)){loop(y-=lowbit(y)){}} 然后查询区间当然是用容斥... 假设查询(x1+1,y1+1)(x2,y2) 那么答案=Q(x1,y1)+Q(x2,y2)-Q(x1,y2)-Q(x2,y1) Q

[bzoj1452][JSOI2009]Count(树状数组)

1452: [JSOI2009]Count Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 2057  Solved: 1216[Submit][Status][Discuss] Description Input Output Sample Input Sample Output 1 2 HINT Source 裸得不能再裸了 暴力100个二维即可 1 #include<stdio.h> 2 #include<stdlib.h> 3

[bzoj1452] [JSOI2009]Count

来自FallDream的博客,未经允许,请勿转载,谢谢. 有一个n*m的矩阵,每个点有一个权值. 需要支持两种操作:1)改变一个点的权值2)查询一个矩形内权值为c的个数 n,m<=300 q<=200000 权值<=100 权值有点小吧?那就每种权值开一个二维树状数组呗 #include<cstdio> #include<iostream> #define MN 300 using namespace std; inline int read() { int x=

BZOJ1452 [JSOI2009]Count Solution

题意:自行脑补 做法:直接开权值那么多的二维树状数组暴力. Code: #include <cstdio> #include <cctype> #include <iostream> #include <algorithm> using namespace std; inline int getc() { static const int L = 1 << 15; static char buf[L], *S = buf, *T = buf; i