magic












P4:magic
这题其实并不难
我们知道xb-xa=2(xd-xc)且xb-xa<(xc-xb)/3且xa<xb<xc<xd
所以我们可以退出:
xb=xa+2i;
xc=xa+8i+k;
xd=xa+9i+k;如图:

__________________________________________
   xa     xb               xc  xd
       2i          6i+k       i
我们可以先枚举xa再枚举i这样我们就可以轻松的知道xb
再枚举k那么我们就可以知道xc和xd的位置(记得加上前缀和和后缀和)
由于它们已经知道位置所以它们一定合法+1 +1 +1 +1
我们知道枚举i的过程中i<n div 8 所以我们就可以优化了。





var
        a,b,c,i,a1,b1,j:longint;
        v:array[1..40000]of longint;
        r:array[1..15000]of longint;
        t:array[1..15000,1..4]of longint;
        s:array[1..100000]of longint;
procedure ss;
begin
        for i:=1 to (a div 8) do
        begin
                b1:=i*2;
                for j:=9*i to a do
                        s[j]:=s[j-1]+r[j-i]*r[j];
                for j:=1 to a-9*i do
                begin
                        if(r[j]<>0)and(r[j+b1]<>0)then
                        begin
                                a1:=s[a]-s[j+9*i];
                                inc(t[j,1],a1*r[j+b1]);
                                inc(t[j+b1,2],a1*r[j]);

                        end;
                end;
                for j:=9*i to a do
                        s[j]:=0;
        end;
end;
procedure yy;
begin
        for i:=1 to a div 8 do
        begin
                b1:=i*2;
                for j:=a-9*i downto 1 do
                        s[j]:=s[j+1]+r[j]*r[j+b1];
                for j:=a downto 9*i+1 do
                begin
                        if(r[j]<>0)and(r[j-i]<>0)then
                        begin
                                a1:=s[1]-s[j-9*i];
                                inc(t[j,4],a1*r[j-i]);
                                inc(t[j-i,3],a1*r[j]);
                        end;
                end;
                for j:=a-9*i downto 1 do
                        s[j]:=0;
        end;
end;
begin
        assign(input,'magic.in');reset(input);
        assign(output,'magic.out');rewrite(output);
        readln(a,b);
        for c:=1 to b do
        begin
                readln(v[c]);
                inc(r[v[c]]);
        end;
        ss;
        yy;
        for c:=1 to b do
        begin
                writeln(t[v[c],1],' ',t[v[c],2],' ',t[v[c],3],' ',t[v[c],4]);
        end;
        close(input);
        close(output); 
end.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值