记录编号 |
208179 |
评测结果 |
AAAAAAAAAA |
题目名称 |
三元数对 |
最终得分 |
100 |
用户昵称 |
FoolMike |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.067 s |
提交时间 |
2015-11-15 16:29:04 |
内存使用 |
1.08 MiB |
显示代码纯文本
var
n,i,j:longint;
x,d:array[1..30000]of longint;
a,b,c:array[1..30000,1..2]of longint;
ans:int64;
procedure merge(l,r,y:longint);
var
m,i,j,k,p:longint;
begin
if l=r then exit;
m:=(l+r) div 2;
merge(l,m,y);
merge(m+1,r,y);
i:=l;j:=m+1;p:=l;
while (i<=m)and(j<=r) do
if (a[i,1]-a[j,1])*y>=0 then
begin
b[p]:=a[i];inc(i);inc(p);
end
else
begin
b[p]:=a[j];
if y=1 then inc(x[a[j,2]],m-i+1);
if y=-1 then inc(d[a[j,2]],m-i+1);
inc(j);inc(p);
end;
if i<=m then
for k:=i to m do
begin
b[p]:=a[k];inc(p);
end
else
for k:=j to r do
begin
b[p]:=a[k];inc(p);
end;
for k:=l to r do
a[k]:=b[k];
end;
begin
assign(input,'three.in');
reset(input);
assign(output,'three.out');
rewrite(output);
read(n);
for i:=1 to n do
begin
read(a[i,1]);
a[i,2]:=i;
end;
c:=a;
merge(1,n,1);
{for i:=1 to n do
writeln(x[i],' ');
writeln;}
a:=c;
for i:=1 to n div 2 do
begin
j:=a[i,1];a[i,1]:=a[n-i+1,1];a[n-i+1,1]:=j;
j:=a[i,2];a[i,2]:=a[n-i+1,2];a[n-i+1,2]:=j;
end;
merge(1,n,-1);
{for i:=1 to n do
writeln(d[i],' ');
writeln;}
for i:=1 to n do
ans:=ans+x[i]*d[i];
writeln(ans);
close(input);
close(output);
end.