UTS Open '21 P7 - April Fools

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type

Inaba is running her own competitive programming website called UTSOJ (UTSOJ: The Splendid Online Judge). As an April Fool's joke, she is planning to give everyone's rating graph a downwards trend! However, she does not want to anger her users too much, so she decides that their rating graph must be stably decreasing. She defines a stably decreasing rating graph as a rating graph where each subsequent rating is either lower than the previous rating, or the left-most bit of the current rating is one position off from the left-most bit of the previous rating. Formally, define MSB(x) as the index of the most significant bit in the binary representation of x. Given a 1-indexed array A with N elements, a permutation of A is defined as stably decreasing if for all i>1, Ai1>Ai or |MSB(Ai1)MSB(Ai)|=1. Since Inaba wants to know how creative she can get, please help her find the number of different stably decreasing permutations of a given array A. Two permutations are considered different if at any index i, the value at index i of the two permutations are different.

Constraints

For this problem, you will NOT be required to pass the sample cases in order to receive points. In addition, you must pass all previous subtasks to earn points for a specific subtask.

For all subtasks:

1N500

1Ai109

All Ai are pairwise distinct.

Subtask 1 [10%]

1N10

Subtask 2 [30%]

1N50

Subtask 3 [20%]

1N100

Subtask 4 [40%]

No additional constraints.

Input Specification

The first line contains an integer N, the length of A.

The next line contains N integers Ai (1iN), representing the elements of array A.

Output Specification

Output one integer, representing the number of different stably decreasing permutations of A. Since this value may be large, output it modulo 109+7.

Sample Input 1

Copy
3
1 3 2

Sample Output 1

Copy
4

Explanation for Sample 1

The four stably decreasing permutations are:

  • [1,3,2] - valid because |MSB(A1)MSB(A2)|=1 and A2>A3.
  • [2,1,3] - valid because A1>A2 and |MSB(A2)MSB(A3)|=1.
  • [3,1,2] - valid because A1>A2 and |MSB(A2)MSB(A3)|=1.
  • [3,2,1] - valid because A1>A2 and A2>A3.

And the two other permutations are:

  • [1,2,3] - invalid because A2<A3 and |MSB(A2)MSB(A3)|1.
  • [2,3,1] - invalid because A1<A2 and |MSB(A1)MSB(A2)|1.

Sample Input 2

Copy
19
1133 1010 1043 1289 1463 1587 1664 1769 1834 1915 1897 1951 1978 2014 2111 2133 2206 2267 2298

Sample Output 2

Copy
994855688

Explanation for Sample 2

Be sure to output your answer modulo 109+7.


Comments

There are no comments at the moment.