Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- int main()
- {
- ll n;
- cin>>n;
- stack<pair<ll,ll>> s;
- for (ll i=1,x; i<=n; i++){
- cin>>x;
- s.push({x,i});
- }
- map<pair<ll,ll>,pair<ll,ll>> mp;
- multiset<pair<ll,ll>> m;
- while(!s.empty()){
- ll a=s.top().first;
- ll b=s.top().second;
- s.pop();
- m.insert({a,b});
- auto it=m.find({a,b});
- if (it==m.begin()){
- mp[{a,b}]={-1,-1};
- }
- else {
- it--;
- mp[{a,b}]=*it;
- it++;
- m.erase(it);
- }
- }
- ll ans[n+1];
- for (auto u:mp){
- if (u.second.first==-1){
- ans[u.first.second]=-1;
- }
- else {
- ans[u.first.second]=u.second.second-u.first.second-1;
- }
- }
- for (ll i=1; i<=n; i++) cout<<ans[i]<<" ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement