int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>T;
while(T–)
{
cin>>n;
intervals.clear();
for(int i = 0; i < n; ++i)
{
cin>>L>>R;
intervals.push_back(make_pair(make_pair(L, R), i));
}
sort(intervals.begin(), intervals.end());
int max_e0 = 0;
int max_e1 = 0;
for(auto p : intervals)
{
int s = p.first.first;
int e = p.first.second;
int label = p.second;
if(max_e0 >= max_e1)
{
color[label] = 1;
max_e1 = max(max_e1, e);
}
else
{
color[label] = 0;
max_e0 = max(max_e0, e);
}
}
for(int i = 0; i < n; ++i)
cout<<color[i];
cout<<endl;
}
}
/*
after challenge end
i tried to understand some of problem by looking at
soln of others but i am not able to understand what logic they have used
same goes to many problems!
*/
Let’s say we color first interval with blue, then afterwards if blue color is colored till x and yellow is colored till y. Now if x > y, in this case we should color the current interval with yellow so that this part can have both colors. And if x < y then we should color the current interval with blue with same reasoning. if x=y, in this case we can use any color. So simply manage 2 arrays one for blue and one for yellow which stores maximum range till which blue and yellow are colored currently. And based on that pick the current color whose range is less.