ACTIV - Activities
Ana likes many activities. She likes acrobatics, alchemy, archery, art, Arabic dances, and
many more. She joined a club that offers several classes. Each class has a time interval
in every week. Ana wants to sign up for many classes, but since they overlap in time, she
looks for a subset of non-overlapping classes to attend. A subset is non-overlapping if it
does not contain two classes that overlap in time. If a class starts at the time another
class ends, this is not considered overlapping.
Ana decided to list all the non-overlapping non-empty subsets of classes. Then she will
choose the subset she likes best. In order to predict the amount of paper needed to write
the list, she wants you to calculate how many of these subsets there are.
Each test case is described using several lines. The first line contains an integer N
indicating the number of classes the club offers (1 ≤ N ≤ 105 ). Each of the next N lines
describes a class using two integers S and E that represent the starting and ending times
of the class, respectively (1 ≤ S < E ≤ 109 ). The end of input is indicated with a line
containing a single −1.
For each test case, output a single line with a single integer representing the number of
non-overlapping non-empty subsets of classes. To make your life easier, output only the
last 8 digits of the result. If the result has less than 8 digits, write it with leading zeros
to complete 8 digits.
How to do this in O(nlogn) , please help. My solution has complexity O(n^2)
AC in one GO !! :D
AC in one go :)
mod=10^8 is correct to retain last 8 digits..............
costed 1 WA for @learnerinblack. :3 Ignore his message. Take modulo 1e8.
Use 10^9 as modulo. Costed me 2 WAs
Can also be done using compression and BIT! Complexity O(NlgN)Last edit: 2018-05-21 13:19:01
learnt how to use upper_bound on structure! , good one!
I keep getting SIGXFSZ error :|
O(2*nlogn) executes in 0.14