eolymp
bolt
Try our new interface for solving problems
Problems

Soldiers Row

published at 1/3/24, 4:38:53 pm

include <bits/stdc++.h>

using namespace std;

int main() { iosbase::syncwith_stdio(0); cin.tie(0);

int n, x;
cin >> n;
stack<pair<int,int>> s;
s.push({1000000000,-1});
for(int i=0; i<n; i++){
    cin >> x;
    while(s.top().first <= x){
        s.pop();
    }
    cout << s.top().second << " ";
    s.push({x,i});
}

}