One-dimensional Game
InterviewTime limit2sMemory limit1024 MB
Given n distinct segments, count for each segment the downward move paths in its containment tree, modulo 1e9+7.
- Level
Medium5 of 10
- Topics
- Sorting, Tree, Dynamic programming
- Solved
- No attempts yet
Statement
Bogdan is playing a game. The game is one-dimensional. There are platforms located on the horizontal line. Bogdan can move between platforms. The -th platform is a horizontal segment . All segments are distinct.
Let's say that the platform is inside the platform if and .
At the beginning of the game, Bogdan chooses the platform from which he will start his journey. Moving between platforms is dangerous and Bogdan tries to stay away from the danger, so he can move from the platform to the platform only if the platform is inside the platform and there is no other platform which is inside the platform and the platform is inside the platform .
For each platform, Bogdan wants to know how many different paths he can take, starting from this platform and ending on any other. Two paths are different if there is a platform which is in one of the paths but not in the other one.
Help Bogdan count the number of paths from each platform. Since the number of paths can be very large, find it modulo .
Input
The first line contains the only integer (), the number of platforms.
The next lines contain the platforms' data. The -th of these lines contains two integers and (), the ends of the -th segment of the platform.
Output
Print integers. The -th integer must be equal to the number of different paths from the platform , modulo .