[BZOJ1452] [JSOI2009]Count

传送门

http://www.lydsy.com/JudgeOnline/problem.php?id=1452

题目大意

支持两个操作
1.修改1个点的权值
2.查询矩阵内某权值出现的次数

题解

建立c棵树状数组,裸的二维树状数组

const
    maxn=305;
    maxm=105;
var
    bit:array[0..maxm,0..maxn,0..maxn]of longint;
    x:array[0..maxn,0..maxn]of longint;
    i,j,k:longint;
    n,m,q,a,b,c,d,e,f:longint;
procedure update(kin,a,b,val:longint);
var tt:longint;
begin
    tt:=b;
    while a<=n do
        begin
            b:=tt;
            while b<=m do
                begin
                    inc(bit[kin,a,b],val);
                    inc(b,b and (-b));
                end;
            inc(a,a and (-a));
        end;
end;

function query(kin,a,b:longint):longint;
var sum,tt:longint;
begin
    sum:=0; tt:=b;
    while a>0 do
        begin
            b:=tt;
            while b>0 do
                begin
                    inc(sum,bit[kin,a,b]);
                    dec(b,b and (-b));
                end;
            dec(a,a and (-a));
        end;
    exit(sum);
end;

begin
    readln(n,m);
    for i:=1 to n do
        for j:=1 to m do
            begin
                read(x[i,j]);
                update(x[i,j],i,j,1);
            end;
    readln(q);
    for i:=1 to q do
        begin
            read(a);
            if a=1
            then begin readln(b,c,d); update(x[b,c],b,c,-1); x[b,c]:=d; update(x[b,c],b,c,1); end
            else begin readln(b,d,c,e,f); writeln(query(f,d,e)-query(f,b-1,e)-query(f,d,c-1)+query(f,b-1,c-1)); end;
        end;
end.

你可能感兴趣的:([BZOJ1452] [JSOI2009]Count)