C11ID - Mã số

Tác giả: ladpro98

Ngôn ngữ: Pascal

program c11id;
uses    math;
const   fi='';
        k=1000000007;
var     res:int64;
        a:array[1..100001] of longint;
        inp:text;
        n,i:longint;

procedure input;
var     i:longint;
begin
        assign(inp,fi);
        reset(inp);
        readln(inp,n);
        for i:=1 to n do readln(inp,a[i]);
        close(inp);
end;


procedure swap(i,j:longint);
var     t:longint;
begin
        t:=a[i];
        a[j]:=a[i];
        a[i]:=a[j];
end;

procedure sort(l,r:longint);
var     pivot:longint;
        i,j:longint;
begin
        if l>=r then exit;
        pivot:=a[random(r-l+1)+l];
        i:=l;j:=r;
        repeat
                while a[i]<pivot do inc(i);
                while a[j]>pivot do dec(j);
                if i<=j then
                begin
                        if i<j then swap(i,j);
                        inc(i);
                        dec(j);
                end;

        until i>j;
        sort(l,j);
        sort(i,r);
end;


begin
        input;
        sort(1,n);
        res:=1;
        for i:=1 to n do
        begin
                res:=(res*((a[i]-i+1) mod k)) mod k;
        end;
        write(res);

end.

Download