#P3773. [CTSC2017] 吉夫特

    ID: 1391 远端评测题 2000ms 489MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2017WC/CTSC/集训队递归O2优化枚举,暴力进制组合数学

[CTSC2017] 吉夫特

Description

A simple problem, both a gift and a poison.

B designed a simple problem to give as a "gift" to everyone.

Given a sequence of length nn, a1,a2,,ana_1, a_2, \cdots , a_n, ask how many non-increasing subsequences of length at least 22 satisfy:

$$\prod _{i=2}^{k} \binom{a_{b_{i-1}}}{a_{b_i}} \bmod 2 = \binom{a_{b_1}}{a_{b_2}} \times \binom{a_{b_2}}{a_{b_3}} \times \cdots \binom{a_{b_{k-1}}}{a_{b_k}} \bmod 2 > 0$$

Output this count modulo 10000000071000000007.

G, after seeing the problem, explained some basic concepts for everyone.

We choose any number of integers bib_i satisfying

1b1<b2<<bk1<bkn1 \leq b_1 < b_2 < \dots < b_{k-1} < b_k \leq n

We call ab1,ab2,,abka_{b_1}, a_{b_2}, \cdots, a_{b_k} a subsequence of aa.

If this subsequence also satisfies

$$a_{b_1} \geq a_{b_2} \geq \cdots \geq a_{b_{k-1}}\geq a_{b_k}$$

we call the subsequence non-increasing.

The binomial coefficient (nm)\binom {n} {m} is the number of ways to choose mm elements from nn distinct elements, computed as follows:

$$\binom {n}{m}=\frac{n!}{m!(n-m)!}=\frac{n \times (n-1) \times \cdots \times 2 \times 1}{(m \times (m-1) \cdots \times 2 \times 1)((n-m)\times(n-m-1)\times \cdots \times 2 \times 1)}$$

Note in particular that since we only consider non-increasing subsequences, it must hold during binomial computation that nmn \geq m, i.e., in (abi1abi)\binom {a_{b_{i-1}}}{a_{b_i}} we always have abi1abia_{b_{i-1}} \geq a_{b_i}.

We emphasize the definition of xmodyx \mod y: $x \bmod y = x -\left \lfloor \frac{x}{y} \right \rfloor \times y$ where n\left \lfloor n \right \rfloor denotes the greatest integer less than or equal to nn.

xmod2>0x \bmod 2 > 0 means that xx is odd.

Meanwhile, experience tells us that a sequence of length nn has O(2n)O(2^n) subsequences, so we take the answer modulo to avoid an overly large output.

B felt that G’s points were very reasonable and reiterated these basics.

Finally, upon hearing that this problem is a "gift" to everyone, G had a piece of advice.

“Vorsicht, Gift!”

“Careful... highly toxic!”

Input Format

The first line contains an integer nn.

Then follow nn lines, each containing one integer. The ii-th of these nn lines is aia_i.

Output Format

Output a single integer, the answer.

4
15
7
3
1
11

Hint

For the first 10%10\% of the test points, n9n \leq 9, 1ai131\leq a_i\leq 13.

For the first 20%20\% of the test points, n17n\leq 17, 1ai201\leq a_i\leq 20.

For the first 40%40\% of the test points, n1911n\leq 1911, 1ai40001\leq a_i\leq 4000.

For the first 70%70\% of the test points, n2017n\leq 2017.

For the first 85%85\% of the test points, n100084n\leq 100084.

For 100%100\% of the test points, 1n2119851\leq n\leq 211985, 1ai2333331\leq a_i\leq 233333. All aia_i are pairwise distinct, that is, there do not exist i,ji, j such that 1i<jn1\leq i < j\leq n and ai=aja_i = a_j.

Translated by ChatGPT 5