暴力枚举
好气,呜呜呜呜呜呜呜
后面才跳出囚牢, 只是模拟而已
C++ 代码
#include <bits/stdc++.h>
using namespace std;
const int N = 5050;
int a[N], b[N], res[N];
inline void solve()
{
int n;
cin >> n;
for (int i = 1; i <= n; i ++ ) cin >> a[i];
for (int i = 1; i <= n; i ++ )
{
memset(b, 0, sizeof b);
int maxv = 0, cnt = 0;
for (int j = i; j <= n; j ++ )
{
b[a[j]] ++;
int t = b[a[j]];
if (t > maxv || t == maxv && cnt > a[j])
maxv = t, cnt = a[j];
res[cnt] ++;
}
}
for (int i = 1; i <= n; i ++ ) cout << res[i] << " ";
}
int main()
{
cin.tie(nullptr) -> sync_with_stdio(0);
solve();
return 0;
}