Files
python/TangDou/CSP-J/AcWingTraining/T6/468_BruteForce_2.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

59 lines
1.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 15010, M = 40010;
int n, m;
int x[M];
LL cnt[N];
LL num[N][4];
// 65分 4层循环,按桶的思路枚举每个魔法值,暴力枚举a,b,c,d
LL read() {
LL x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("468.in", "r", stdin);
#endif
n = read(), m = read();
for (int i = 1; i <= m; i++) {
x[i] = read();
cnt[x[i]]++;
}
for (int a = 1; a <= n; a++)
for (int b = a + 1; b <= n; b++)
for (int c = b + 1; c <= n; c++)
for (int d = c + 1; d <= n; d++) {
if ((b - a) & 1 || 3 * (b - a) >= (c - b)) continue;
if ((b - a) != 2 * (d - c)) continue;
LL ans = cnt[a] * cnt[b] * cnt[c] * cnt[d];
num[a][0] += ans;
num[b][1] += ans;
num[c][2] += ans;
num[d][3] += ans;
}
for (int i = 1; i <= n; i++)
for (int j = 0; j < 4; j++)
num[i][j] /= cnt[i] ? cnt[i] : 1;
for (int i = 1; i <= m; i++) {
for (int j = 0; j < 4; j++)
printf("%lld ", num[x[i]][j]);
puts("");
}
return 0;
}