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.


1 3
3 5
5 7
2 4
4 6
500000000 1000000000
1 500000000
1 500000000
999999999 1000000000
-1 Output:

hide comments
kshubham02: 2017-08-30 10:34:49

I keep getting SIGXFSZ error :|
Wiki says that this signal indicates I am exceeding output file size. I don't understand why such a thing may be happening.
Please look into it : Submission Id - 20064346

nk17kumar: 2017-06-19 21:30:37

O(2*nlogn) executes in 0.14

holmesherlock: 2017-05-24 21:25:04

easy but take care of the modulus ..

vishalsingh: 2017-01-25 19:41:50

can any one help my code gives wrong ans in O(nlogn + nlogn) implementation

darkod3r: 2016-07-16 21:39:08

easy one! basic dp + binary search. just take care of MOD ;)

Last edit: 2016-07-16 21:40:11
Ravi kumar: 2015-07-21 19:06:26

dp+bit :)

vivek singh rana: 2015-06-25 17:36:02

test case-
1 2
2 3
3 4
1 8
4 5
5 6


Shubham: 2015-05-29 13:00:25

easy one silly mistake caused me so many WA......keep in mind ans will have 8 digits so dp value must be kept under 10^8 by taking mod :)

Anmol Pandey: 2015-01-17 21:59:13

Nice Problem.
NlogN+Nlong passes

Rishav Goyal: 2014-05-29 20:50:23

sorting reverse made me 3 WA's :/

Added by:Pablo Ariel Heiber
Time limit:2.365s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 NODEJS OBJC VB.NET
Resource:FCEyN UBA ICPC Selection 2010