#P6856. 「EZEC-4.5」子序列

    ID: 5868 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>递推线段树块状链表,块状数组,分块

「EZEC-4.5」子序列

Description

Given a sequence aa with nn elements.

Define the value of a sequence ss with xx elements as:

$$\sum \limits _{i=1} ^ x s_i \times \prod \limits _{i=1} ^ x s_i$$

Represent an xx-element subsequence of aa as s={ap1,ap2,...,apx}s = \{a_{p_1}, a_{p_2}, ..., a_{p_x}\}, where pp is a strictly increasing sequence and 1p1pxn1 \le p_1 \le p_x \le n.

Given an integer kk, define that an xx-element subsequence ss of aa is legal if it satisfies pxp1kp_x - p_1 \le k.

Compute, modulo modmod, the sum of the values of all legal subsequences of aa.

Input Format

The first line contains three integers, n,k,modn, k, mod.

The second line contains nn integers, aia_i.

Output Format

Output one integer, the answer modulo modmod.

4 1 1000000007
1 2 3 4
150
3 2 114
2 3 4
65
12 8 10042020
1 1 4 5 1 4 1 9 1 9 8 10
2797740

Hint

Large sample

Sample Explanation.

Sample 1.

  • All legal subsequences are $\{1\}, \{2\}, \{3\}, \{4\}, \{1,2\}, \{2,3\}, \{3,4\}$.

  • The answer is $1 \times 1 + 2 \times 2 + 3 \times 3 + 4 \times 4 + (1+2) \times 1 \times 2 + (2+3) \times 2 \times 3 + (3+4) \times 3 \times 4 = 150$.

Sample 2.

  • All legal subsequences are $\{2\}, \{3\}, \{4\}, \{2,3\}, \{3,4\}, \{2,4\}, \{2,3,4\}$. The answer is 407mod114=65407 \mod 114 = 65.

Constraints.

Test point ID nn \le Special property
141 \sim 4 2020 None
5115 \sim 11 10310^3
1212 10610^6 k=0k=0
131413 \sim 14 10510^5 ai=1a_i=1
151715 \sim 17 mod=109+7mod=10^9+7
182218 \sim 22 None
232523 \sim 25 10610^6
  • For 100%100\% of the testdata, 0k<n1060 \le k < n \le 10^6, 1ai1091 \le a_i \le 10^9, 1mod109+71 \le mod \le 10^9+7.

Translated by ChatGPT 5