Mock CCC '19 Contest 1 S5 - Naruto and Sasuke

View as PDF

Submit solution

Points: 60 (partial)
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type
Naruto (young) performing his Shadow Clone Jutsu.

Naruto's signature jutsu is the shadow clone jutsu. He can create over 200000 clones of himself!

On a line, Naruto has created N copies of himself. He has numbered each of his clones from 1 to N. His i^{th} clone, located at position P_i, will begin walking with a velocity of V_i towards the positive direction at time 0.

As Sasuke and Naruto are such great rivals, Sasuke has mastered a... new type of jutsu. At time 0, he can choose a number of shadow clones, and that clone will turn into a clone of Sasuke! When the clone turns into Sasuke, the velocity and position of the clone will not change, and it will continue walking towards the positive direction. Furthermore, once a Sasuke clone touches another Naruto clone, the Naruto clone will become a Sasuke clone!

There are many clones Sasuke could choose at time 0 to transform all of the Naruto clones to Sasuke clones. How many ways will all of Naruto's clones turn into Sasuke clones after an infinitely large amount of time?

Constraints

  • 1 \le N \le 200000
  • 1 \le P_i, V_i \le 10^9, such that 1 \le i \le N
  • All values of P_i will be distinct, and so will V_i.

Input Specification

The first line of input will contain an integer N.

The next N lines of input will contain 2 space separated integers, P_i and V_i.

Output Specification

You are to output a single integer, the number of ways at time 0 to change a number of Naruto clones to Sasuke clones, modulo 10^9 + 7.

Sample Input 1

3
2 5
6 1
3 7

Sample Output 1

6

Sample Explanation

After an infinitely large amount of time, the ways Sasuke could choose clones at time 0 are:

(2), (3), (1, 2), (1, 3), (2, 3), (1, 2, 3).


Comments

There are no comments at the moment.