Gravatar
SUNYU
积分:51
提交:153 / 285
var
a,l,r,c:array[0..50100]of int64;
i,j,k,m,n:longint;
ans:int64;
function low(x:longint):longint;
begin
exit(x and (x xor(x-1)));
end;
procedure change(i,k:longint);
begin
while i<=35000 do
begin
c[i]:=c[i]+k;
i:=i+low(i);
end;
end;
function sum(i:longint):longint;
var
s:longint;
begin
s:=0;
while i>0 do
begin
s:=s+c[i];
i:=i-low(i);
end;
exit(s);
end;
begin
assign(input,'e:\1.txt');reset(input);
//assign(output,'queueb.out');rewrite(output);
read(n);
for i:=1 to n do read(a[i]);
for i:=1 to n do a[i]:=a[i]+1;//另外树状数组不能处理下标为1的情况,因为low函数一直返回0,会死循环,所以各加1
for i:=1 to n do
begin
change(a[i],1);
l[i]:=sum(a[i]-1);
end;
fillchar(c,sizeof(c),0);
for i:=n downto 1 do
begin
change(a[i],1);
r[i]:=sum(a[i]-1);
end;
for i:=1 to n do
ans:=ans+l[i]*r[i];
writeln(ans);
close(output);
end.

题目 859 数列
2014-07-07 16:46:12
Gravatar
QhelDIV
积分:2339
提交:638 / 1737
写完平衡树忘了把暴力程序代码删掉。。。。。

题目 859 数列
2013-04-07 15:55:02
Gravatar
as
积分:48
提交:7 / 28
终于摇头晃脑地过了,撒花庆祝!

题目 859 数列
2012-11-09 21:33:49