树状数组

来源:互联网 发布:灯塔软件 编辑:程序博客网 时间:2024/05/29 17:27

树状数组就线段树来说 无法进行区间修改和求最值

program pro;type mine=array[0..100000]of longint;var        n,m:longint;        a,b:mine;        st,i,j,x,y:longint;function f(xx:longint):longint;begin        exit(xx and (-xx));end;procedure plus(var sz:mine; xx:longint);//修改var     tmp:longint;begin        while (xx<=n) do        begin                inc(sz[xx]);                inc(xx,f(xx));        end;end;function sum(var sz:mine; xx:longint):longint;//求和var     tot:longint;begin        tot:=0;        while xx>0 do        begin                inc(tot,sz[xx]);                dec(xx,f(xx));        end;        exit(tot);end;begin        readln(n,m);        for i:=1 to m do        begin                read(st,x,y);                if st=1 then                begin                        plus(a,x);                        plus(b,y);                end                else                begin                        writeln(sum(a,y)-sum(b,x-1));                end;        end;end.



0 0
原创粉丝点击