
树状数组 + 离散化
#include
#include
#include
#include
using namespace std;
const int N = 1e5 + 10;
int n;
int tr[N], a[N];
vector<int> alls;
int res[N];
int lowbit(int x)
{
return x & -x;
}
void add(int x, int c)
{
for(int i = x; i <= n; i += lowbit(i))
tr[i] = max(tr[i], c);
}
int query(int x)
{
int res = 0;
for(int i = x; i; i -= lowbit(i))
res = max(res, tr[i]);
return res;
}
int find(int x)
{
int l = 0, r = alls.size() - 1;
while(l < r)
{
int mid = (l + r + 1) >> 1;
if(alls[mid] <= x)
l = mid;
else
r = mid - 1;
}
return r + 1;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
alls.push_back(a[i]);
}
sort(alls.begin(), alls.end());
alls.erase(unique(alls.begin(), alls.end()), alls.end());
for(int i = n; i ;i --)
{
int x = find(a[i]);
add(x, i);
int t = query(x - 1);
if(t <= i) res[i] = -1;
else res[i] = t - i - 1;
}
for(int i = 1; i <= n; i ++)
cout << res[i] << " ";
cout << endl;
return 0;
}