➤ Problem Link : 1000C. Covered Points Count
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
int n;
cin>>n;
map<ll,ll> ms;
vector<ll> ans(n+1,0);
ll x,y;
for(int i=1;i<=n;i++)
{
cin>>x>>y;
ms[x]++;
ms[y+1]--;
}
ll curr=0,prev;
for(auto it = ms.begin();it!=ms.end();it++)
{
if(it!=ms.begin())
{
ans[curr]+=it->first-prev;
}
prev=it->first;
curr+=it->second;
}
for(ll i=1;i<=n;i++)
cout<<ans[i]<<" ";
}
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!!
