题目: |
type arr=array[0..100000]of longint;
var
c, q, d, e, ans: arr;
n, i: longint;
procedure merge(a, b: longint);
var
mid, i, j, p: longint;
begin
mid := (a+b) div 2;
if a < mid then merge(a, mid);
if mid+1 < b then merge(mid+1, b);
p:=0; i:=a; j:=mid+1;
while (i <= mid) and (j <= b) do
begin
if c[i] >= c[j] then
begin
p := p+1; d[p] := c[i]; e[p] := q[i]; i := i+1;
end
else
begin
p := p+1; d[p] := c[j]; e[p] := q[j];
j := j+1; inc(ans[e[p]], mid-i+1);
end;
end;
while (i <= mid) and (j > b) do
begin
p := p+1; d[p] := c[i]; e[p] := q[i]; i := i+1;
end;
while (i > mid) and (j <= b) do
begin
p := p+1; d[p] := c[j]; e[p] := q[j]; j := j+1;
end;
for i := a to b do
begin
c[i] := d[i-a+1]; q[i] := e[i-a+1];
end;
end;
begin
readln(n);
for i := 1 to n do
begin
read(c[i]); q[i] := i;
end;
merge(1, n);
for i := 1 to n-1 do
write(ans[i], ’,’);
writeln(ans[n]);
end.
输入
5
4 3 1 2 5 输出:0,0,0,1,4
|