1452: [JSOI2009]Count - BZOJ

來源:互聯網
上載者:User

標籤:des   c   style   class   blog   code   

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 var10     i:longint;11 begin12     while x<=n do13       begin14         i:=y;15         while i<=m do16           begin17             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 var26     i:longint;27 begin28     sum:=0;29     while x>0 do30       begin31         i:=y;32         while i>0 do33           begin34             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 var43     i,j,x1,y1,x2,y2,c:longint;44 begin45     read(n,m);46     for i:=1 to n do47       for j:=1 to m do48         begin49           read(a[i,j]);50           add(s[a[i,j]],i,j,1);51         end;52     read(q);53     for i:=1 to q do54       begin55         read(j);56         if j=1 then57           begin58             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           end63         else64           begin65             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 begin72     main;73 end.
View Code

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.