➤ Problem Link : 652D. Nested Segments
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define pp pair<ll,ll>
#define ppp pair<pp,ll>
#define mp make_pair
int main()
{
ordered_set oset;
int n;
cin>>n;
ppp arr[n];
vector<ll> ans(n);
for(int i=0;i<n;i++)
{
cin>>arr[i].first.second>>arr[i].first.first;
arr[i].second=i;
}
sort(arr,arr+n);
for(int i=0;i<n;i++)
{
ans[arr[i].second]=oset.order_of_key(arr[i].first.second);
oset.insert(arr[i].first.second);
}
for(int v : ans)
cout<<v<<"\n";
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
