比赛 20120709 评测结果 AAAAAAAAAA
题目名称 数列 最终得分 100
用户昵称 czp 运行时间 0.046 s
代码语言 Pascal 内存使用 1.01 MiB
提交时间 2012-07-09 11:49:20
显示代码纯文本
var
 c,a,f,g:array[0..55555] of longint;
 i,j,m,n:longint;
 v1,v2,ans:int64;
function low(x:longint):longint;
begin low:=x and (-x); end;
procedure plus(k,date:longint);
begin
 while k<32769 do
  begin
   inc(c[k],date);
   inc(k,low(k));
  end;
end;
function sum(k:longint):longint;
var u:longint;
begin
  u:=0;
  while k>0 do
   begin
    inc(u,c[k]);
    dec(k,low(k));
   end;
  sum:=u;
end;
begin
 assign(input,'queueb.in');reset(input);
 assign(output,'queueb.out');rewrite(output);
 readln(n);
 for i:=1 to n do
  begin readln(a[i]);inc(a[i]); end;
 for i:=1 to n do
  begin
   f[i]:=sum(a[i]-1);
   plus(a[i],1);
  end;
 fillchar(c,sizeof(c),0);
 for i:=n downto 1 do
  begin
   g[i]:=sum(a[i]-1);
   plus(a[i],1);
  end;
 for i:=2 to n-1 do
  begin
   v1:=f[i];
   v2:=g[i];
   ans:=ans+v1*v2;
  end;
 writeln(ans);
 close(input);close(output);
end.