#include <string>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
vector<int> solution(vector<int> prices) {
int n = prices.size();
vector<int> answer(n, 0);
// index, price, second
queue<pair<pair<int, int>, int>> q;
q.push({{0, prices[0]}, 0});
for (int i = 1; i < n; i++)
{
int q_size = q.size();
while (q_size > 0)
{
auto [index_price, second] = q.front();
q.pop();
int index = index_price.first;
int price = index_price.second;
second++;
if (price <= prices[i])
{
q.push({{index, price}, second});
}
else
{
answer[index] = second;
}
q_size--;
}
q.push({{i, prices[i]}, 0});
}
while (!q.empty())
{
auto [index_price, second] = q.front();
q.pop();
int index = index_price.first;
answer[index] = second;
}
return answer;
}