1452: [JSOI2009]Count - BZOJ

Description

1452: [JSOI2009]Count - BZOJ
Input

1452: [JSOI2009]Count - BZOJ
Output

1452: [JSOI2009]Count - BZOJ
Sample Input

1452: [JSOI2009]Count - BZOJ

Sample Output

1

2
HINT

1452: [JSOI2009]Count - BZOJ

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

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

 type
tree=array[..,..]of longint;
var
s:array[..]of tree;
a:array[..,..]of longint;
n,m,q:longint; procedure add(var c:tree;x,y,w:longint);
var
i:longint;
begin
while x<=n do
begin
i:=y;
while i<=m do
begin
inc(c[x,i],w);
i:=i+(i and (-i));
end;
x:=x+(x and (-x));
end;
end; function sum(var c:tree;x,y:longint):longint;
var
i:longint;
begin
sum:=;
while x> do
begin
i:=y;
while i> do
begin
inc(sum,c[x,i]);
i:=i-(i and (-i));
end;
x:=x-(x and (-x));
end;
end; procedure main;
var
i,j,x1,y1,x2,y2,c:longint;
begin
read(n,m);
for i:= to n do
for j:= to m do
begin
read(a[i,j]);
add(s[a[i,j]],i,j,);
end;
read(q);
for i:= to q do
begin
read(j);
if j= then
begin
read(x1,y1,c);
add(s[a[x1,y1]],x1,y1,-);
a[x1,y1]:=c;
add(s[c],x1,y1,);
end
else
begin
read(x1,x2,y1,y2,c);
writeln(sum(s[c],x2,y2)+sum(s[c],x1-,y1-)-sum(s[c],x1-,y2)-sum(s[c],x2,y1-));
end;
end;
end; begin
main;
end.
上一篇:Openstack学习目录


下一篇:基于vitamio的网络电视直播源码