My submission is partially correct, i.e. it got AC for lower inputs but got WA at higher inputs.

I used the logic given in the editorial https://discuss.codechef.com/problems/UNICOLOR

I used 2d array implementation of Graph. I sorted all the intervals on the basis of their left end. I stored the club number which they belong to along with the intervals. If anything was common then added an edge between the clubs. If nothing was common then I added the difference between the intervals to the variable which stores the number of students not in any club. Then I calculated the number of components using DFS. Then called the fastpow() function to calculate the final answer.

It would be really helpful if the community can help me completely solve the problem.

Thank you in advance

P.S. (I have used long long int everywhere, even then I got WA on higher inputs)

Here’s the link to my submission https://www.codechef.com/viewsolution/44342526