Intersection of intervals
Practice
4 (18 votes)
Combinatorics
Math
Medium
Problem
54% Success 1102 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Let $$S$$ be a set of intervals of integers and $$f(S)$$ be the number of integers $$x$$ for which there exist an interval $$T$$ with $$T \in S$$ and $$x, x+1 \in T$$. In particular we have that $$f(\{ [l,r] \}) = r - l$$.

Given an integer array $$A$$ of length $$2N$$. Consider a sequence of intervals $$[l_1, r_1], [l_2, r_2], \dots, [l_N, r_N]$$ valid if $$r_1 < r_2 < \dots < r_N$$, $$l_i < r_i$$ and $$(l_1, r_1, l_2, r_2, \dots, l_N, r_N)$$ is a permutation of $$A$$.

Find the sum $$f(\{ [l_1, r_1] \} \cup \{ [l_2, r_2] \} \cup \dots \cup \{ [l_N, r_N] \})$$ modulo $$10^9 + 7$$ over all possible sequences of intervals.

$$\textbf{Input}$$

The first line contains one integer - $$N (1 \le N \le 10^5)$$.

The next line contains $$2N$$ integers - $$A_1, A_2, \dots, A_{2N}$$ $$(1 \le A_1 < A_2 < \dots < A_{2N} \le 10^9)$$.

$$\textbf{Output}$$

Output the answer modulo $$10^9 + 7$$.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
5 votes
Tags:
Modular arithmeticCombinatoricsNumber theoryPrime FactorizationBasics of CombinatoricsAlgorithmsModular exponentiationMath
Points:30
7 votes
Tags:
CombinatoricsBasics of CombinatoricsMathC++
Points:30
1 votes
Tags:
CombinatoricsMathMedium