记录编号 |
119827 |
评测结果 |
AAAAAAAAAA |
题目名称 |
三元数对 |
最终得分 |
100 |
用户昵称 |
稠翼 |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.102 s |
提交时间 |
2014-09-14 15:22:49 |
内存使用 |
2.46 MiB |
显示代码纯文本
program cogs1260;
var
a,b,c:array[0..50000,0..1]of int64;
l,r,j,i,k,n:longint;
ans:int64;
procedure init;
begin
assign(input,'three.in');reset(input);
assign(output,'three.out');rewrite(output);
end;
procedure sort(l,r:longint);
var
mid:longint;
begin
if l>=r then exit;
mid:=(l+r)shr 1;
sort(l,mid);
sort(mid+1,r);
k:=l;i:=l;j:=mid+1;
while k<=r do
begin
if(a[i,0]<a[j,0])and(i<=mid)and(j<=r) then
begin
b[k,0]:=a[i,0];
b[k,1]:=a[i,1];
inc(c[a[i,1],1],r-j+1);
inc(k);
inc(i);
end
else if (a[i,0]>=a[j,0])and(i<=mid)and(j<=r) then
begin
b[k,0]:=a[j,0];
b[k,1]:=a[j,1];
inc(c[a[j,1],0],i-l);
inc(k);
inc(j);
end else
if i>mid then
begin
b[k,0]:=a[j,0];
b[k,1]:=a[j,1];
inc(c[a[j,1],0],i-l);
inc(k);
inc(j);
end else
if j>r then
begin
b[k,0]:=a[i,0];
b[k,1]:=a[i,1];
inc(k);
inc(i);
end;
end;
for i:=l to r do
begin
a[i,0]:=b[i,0];
a[i,1]:=b[i,1];
end;
end;
procedure main;
begin
readln(n);
for i:=0 to n-1 do
begin
readln(a[i,0]);
a[i,1]:=i+1;
end;
sort(0,n-1);
for i:=0 to n-1 do inc(ans,c[i,0]*c[i,1]);
writeln(ans);
end;
begin
init;
main;
close(output);
end.//complete by chouyi20140913