BZOJ1452: [JSOI2009]Count

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   os   io   for   

1452: [JSOI2009]CountTime Limit: 10 Sec  Memory Limit: 64 MB
Submit: 1062  Solved: 625
[Submit][Status]DescriptionInputOutputSample Input

Sample Output1
2HINT



Source

JSOI2009Day1

題解:

暴力維護100棵樹狀數組。。。

為什麼 inc(i,i and (-i))就TLE,寫成 i:=i+i and (-i)就尼瑪A了。。。

代碼:

 1 const maxn=300+10; 2 type arr=array[0..maxn,0..maxn] of longint; 3 var s:array[0..100+10] of arr; 4     a:array[0..maxn,0..maxn] of longint; 5     i,j,n,m,q,x,y,x1,y1,x2,y2,z,ch:longint; 6 procedure add(var c:arr;x,y,z:longint); 7  var i:longint; 8  begin 9   while x<=n do10    begin11      i:=y;12      while i<=m do13       begin14         inc(c[x,i],z);15         i:=i+i and (-i);16       end;17      x:=x+x and (-x);18    end;19  end;20 function sum(c:arr;x,y:longint):longint;21  var i:longint;22  begin23   sum:=0;24   while x>0 do25     begin26       i:=y;27       while i>0 do28         begin29           inc(sum,c[x,i]);30           i:=i-i and (-i);31         end;32       x:=x-x and (-x);33     end;34  end;35 36 procedure init;37  begin38    readln(n,m);39    for i:=1 to n do40     begin41       for j:=1 to m do42        begin43          read(a[i,j]);44          add(s[a[i,j]],i,j,1);45        end;46       readln;47     end;48  end;49 procedure main;50  begin51    readln(q);52    for i:=1 to q do53     begin54       read(ch);55       case ch of56       1:begin57         readln(x,y,z);58         add(s[a[x,y]],x,y,-1);59         add(s[z],x,y,1);60         a[x,y]:=z;61         end;62       2:begin63         readln(x1,x2,y1,y2,z);64         writeln(sum(s[z],x2,y2)-sum(s[z],x2,y1-1)-sum(s[z],x1-1,y2)+sum(s[z],x1-1,y1-1));65         end;66       end;67     end;68  end;69 begin70     assign(input,‘input.txt‘);assign(output,‘ouput.txt‘);71     reset(input);rewrite(output);72     init;73     main;74     close(input);close(output);75 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.