POJ1990 MooFest——树状数组
来源:互联网 发布:云计算技术及应用 编辑:程序博客网 时间:2024/05/01 08:07
维护两个树状数组,一个记录这个坐标所控制的范围内的奶牛个数,另外一个记录这个坐标所控制范围内的奶牛坐标之和。
CODE
Program POJ1990;//By_PoetshyConst maxn=20000;Vari,n:Longint;p,m,ans:Int64;v,x,a,h:Array[1..maxn]of Int64;Procedure Qsort(l,r:Longint);var i,j,k,temp:Longint;begini:=l;j:=r;k:=v[(i+j)>>1];repeatwhile v[i]<k do inc(i);while v[j]>k do dec(j);if i<=j then begintemp:=x[i];x[i]:=x[j];x[j]:=temp;temp:=v[i];v[i]:=v[j];v[j]:=temp;inc(i);dec(j);end;until i>j;if i<r then Qsort(i,r);if l<j then Qsort(l,j);end;Function Count(i:Longint):Int64;beginCount:=0;while i>0 do begininc(Count,a[i]);dec(i,(i)and(-i));end;end;Function Counth(i:Longint):Int64;beginCounth:=0;while i>0 do begininc(Counth,h[i]);dec(i,(i)and(-i));end;end;Procedure Deal(i:Longint);var j:Longint;beginj:=x[i];while j<=maxn do begininc(a[j]);inc(h[j],x[i]);inc(j,j and(-j));end;end;BEGINreadln(n);for i:=1 to n do readln(v[i],x[i]);Qsort(1,n);for i:=1 to n do beginp:=Count(x[i]);m:=Counth(x[i]);inc(ans,v[i]*(p*x[i]-m));p:=Count(maxn)-p;m:=counth(maxn)-m;inc(ans,v[i]*(m-p*x[i]));Deal(i);end;writeln(ans);END.
- POJ1990 MooFest——树状数组
- POJ1990 MooFest,树状数组
- poj1990 moofest 树状数组
- POJ1990 MooFest(树状数组)
- 【树状数组--思维】poj1990 MooFest
- poj1990 MooFest && hdu3015 Disharmony Trees (树状数组)
- POJ1990 MooFest 树状数组(Binary Indexed Tree,BIT)
- poj1990~MooFest(哥拿下的第一个树状数组)
- poj1990 树状数组+排序
- poj1990&&uva1428 树状数组
- poj1990两个树状数组
- POJ1990-MppFest-树状数组
- POJ1990 (树状数组)
- poj1990 MooFest
- poj1990 MooFest
- poj1990 MooFest
- POJ1990-MooFest
- poj1990 MooFest
- 64bit win7 oracle11gR2 installation
- 什么是C/S架构B/S架构
- apache 设置禁止访问某些文件或目录
- gsettings
- 水晶报表中"已达到系统管理员配置的最大报表处理作业数限制"错误的处理 .
- POJ1990 MooFest——树状数组
- 无向图的最小生成树算法的C程序实现代码(Prim算法)
- WCF中 改名后 无法找到 ServiceHost 指令中作为服务属性值提供的类型“WCFDemo.Service1”。
- C语言的sizeof和strlen
- 中关村示范区两项人才特区政策落地
- 怎样提高视力--非常简单使用的方法
- 博客终于开通了
- 触发器TRIGGER的编写与调试
- 自定义TextView带滚动字幕