First note that, taking any non-empty subset of {1,2,,n}\{ 1, 2, \cdots, n \}gives us a subsequence, namely the subsequence indices from that set. So we first count the subsequences containing only one distinct value. Suppose the array has value xx at kk indices, then any non-empty subset of those kk indices will create a subsequence containing only xx. Hence number of subsequence containing only one value is x2cntx1\sum _x 2^{cnt_x} - 1where cntxcnt_x is the count of occurrences of xx.

For the subsequences containing exactly two distinct values, we take all possible pairwise product of 2cntx12^{cnt_x}-1 and sum them. All of this needs to be done modulo 109+710^9+7

Contributors

Statistics

83% Solution Ratio
Farhan20Earliest, Nov '21
nusuBotFastest, 0.0s
Zobayer_AbedinLightest, 1.7 MB
mustafiz_voidShortest, 762B
Toph uses cookies. By continuing you agree to our Cookie Policy.