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.