1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
using namespace std;

int t[200005];

vector<int> sc[200005];

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> t[i];
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j < i; j++)
        {
            if (t[j] > t[i])
            {
                sc[i].push_back(j);
                sc[j].push_back(i);
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        queue<pair<int, int>> bfs;
        vector<bool> odw(n + 1);
        bfs.push({i, 0});
        long long wn = 0;
        odw[i] = 1;
        while (bfs.size())
        {
            pair<int, int> tp = bfs.front();
            bfs.pop();
            wn += tp.second;
            for (auto i : sc[tp.first])
            {
                if (odw[i] == 0)
                {
                    odw[i] = 1;
                    bfs.push({i, tp.second + 1});
                }
            }
        }
        cout<<wn<<' ';
    }
}