记录编号 |
39345 |
评测结果 |
AAAAAAAAAA |
题目名称 |
数列 |
最终得分 |
100 |
用户昵称 |
wo shi 刘畅 |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.065 s |
提交时间 |
2012-07-09 15:11:36 |
内存使用 |
38.31 MiB |
显示代码纯文本
var
i:longint;
ans,n:int64;
a,f,s,zuo,you:Array[0..1000000]of int64;
function lowbit(k:int64):int64;
begin
lowbit:=k and (-k);
end;
function lowbi(k:int64):int64;
begin
lowbi:=k and (-k);
end;
procedure change(k,x:int64);
begin
while k<=32768 do
begin
inc(f[k],x);
inc(k,lowbit(k));
end;
end;
procedure chang(k,x:int64);
begin
while k<=32768 do
begin
inc(s[k],x);
inc(k,lowbi(k));
end;
end;
function sum(k:int64):int64;
var
num:int64;
begin
num:=0;
while k>0 do
begin
inc(num,f[k]);
dec(k,lowbit(k));
end;
sum:=num;
end;
function su(k:int64):int64;
var
num:int64;
begin
num:=0;
while k>0 do
begin
inc(num,s[k]);
dec(k,lowbit(k));
end;
su:=num;
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]);
inc(a[i]);
end;
change(a[1],1);
for i:=2 to n do
begin
zuo[i]:=sum(a[i]-1);
change(a[i],1);
end;
chang(a[n],1);
for i:=n-1 downto 1 do
begin
you[i]:=su(a[i]-1);
chang(a[i],1);
end;
ans:=0;
for i:=2 to n-1 do ans:=ans+zuo[i]*you[i];
writeln(ans);
close(input);
close(output);
end.