P2119 魔法阵
%%%
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<math.h>
#define ls (p<<1)
#define rs (p<<1|1)
#define mid (l+r)/2
#define over(i,s,t) for(register int i=s;i<=t;++i)
#define lver(i,t,s) for(register int i=t;i>=s;--i)
using namespace std;
typedef long long ll;
const ll N=1000007;
const ll INF=1e9+9;
const ll mod=2147483647;
const double EPS=1e-10;
const double Pi=3.1415926535897;
ll n,m,a[N],b[N],c[N],d[N];
ll x[N],vis[N];
int main()
{
scanf("%lld%lld",&n,&m);
over(i,1,m)
scanf("%lld",&x[i]),vis[x[i]]++;
for(int t=1;9*t<n;++t)
{
ll sum=0;
for(int D=9*t+2;D<=n;++D)
{
ll A=D-9*t-1;
ll B=A+2*t;
ll C=D-t;
sum+=vis[A]*vis[B];
c[C]+=sum*vis[D];
d[D]+=sum*vis[C];
}
sum=0;
for(int A=n-9*t-1;A;--A)
{
ll B=A+2*t;
ll C=A+8*t+1;
ll D=A+9*t+1;
sum+=vis[C]*vis[D];
a[A]+=vis[B]*sum;
b[B]+=vis[A]*sum;
}
}
over(i,1,m)
printf("%lld %lld %lld %lld\n",a[x[i]],b[x[i]],c[x[i]],d[x[i]]);
return 0;
}