记录编号 39351 评测结果 AAAAAAAAAA
题目名称 数列 最终得分 100
用户昵称 Gravatarfuhao 是否通过 通过
代码语言 Pascal 运行时间 0.053 s
提交时间 2012-07-09 15:12:20 内存使用 0.66 MiB
显示代码纯文本
const maxn=50001; maxa=40000;
var
 l,r,ans:int64; a:array[0..maxn] of longint;
 sum_l,sum_r:array[0..maxa] of longint;
 n,i:longint;
 function lowbit(k:longint):longint;
 begin exit(k and (-k)); end;
 function getsum_left(k:longint):longint;
 var t:longint;
 begin
  t:=0;
  while k>0 do
   begin
    t:=t+sum_l[k];
    k:=k-lowbit(k);
   end;
  getsum_left:=t;
 end;
 function getsum_right(k:longint):longint;
 var t:longint;
 begin
  t:=0;
  while k>0 do
   begin
    t:=t+sum_r[k];
    k:=k-lowbit(k);
   end;
  exit(t);
 end;
 procedure insert_right(k:longint);
 begin
  while k<=maxa do
   begin
    inc(sum_r[k]);
    k:=k+lowbit(k);
   end;
 end;
 procedure delete_right(k:longint);
 begin
  while k<=maxa do
   begin
    dec(sum_r[k]);
    k:=k+lowbit(k);
   end;
 end;
 procedure insert_left(k:longint);
 begin
  while k<=maxa do
   begin
    inc(sum_l[k]);
    k:=k+lowbit(k);
   end;
 end;
begin
 assign(input,'queueb.in'); reset(input);
 assign(output,'queueb.out'); rewrite(output);
 readln(n);
 for i:=1 to n do
  begin
   read(a[i]);
   a[i]:=a[i]+1;
   insert_right(a[i]);
  end;
 for i:=1 to n do
  begin
   delete_right(a[i]);
   l:=getsum_left(a[i]-1);
   r:=getsum_right(a[i]-1);
   ans:=ans+l*r;
   insert_left(a[i]);
  end;
 writeln(ans);
 close(input); close(output);
end.