#P10886. 【MX-S3-T2】「FeOI Round 1」Journey

【MX-S3-T2】「FeOI Round 1」Journey

Background

Original link: https://oier.team/problems/S3B


Problem Description

Little W has recently been learning a programming language.

This programming language has a statement as follows:

range(a,b,c)

This statement represents a sequence, and the sequence is:

[a,a+c,a+2c,,a+kc][a,a+c,a+2c,\cdots,a+kc]

Here, kk is the largest non-negative integer kk such that a+kc<ba+kc<b. For example, range(1,7,2) represents the sequence [1,3,5][1,3,5].

Little W wants to ask you a question: given a sequence gg of length nn (indexed starting from 11), compute the value of the following expression, and output the answer modulo 109+710^9 +7.

$$\sum_{a=1}^{n}\sum_{b=a+1}^{n+1}\sum_{c=1}^{n}\sum\limits_{i\in \mathrm{range}(a,b,c)} g_i$$

Input Format

To speed up input, we use the following input method.

The input consists of one line with five non-negative integers n,A,B,C,gnn, A, B, C, g_n.

Here, nn is the length of the sequence gg, A,B,CA, B, C are parameters for generating the data, and gng_n is the nn-th term of the sequence gg.

For the ii-th term of the sequence gg (1i<n1\leq i < n), it satisfies giAgi+12+Bgi+1+C(mod109+7)g_i \equiv Ag_{i+1}^2+Bg_{i+1}+C \pmod {10^9 + 7}.

Output Format

Output one line with one non-negative integer, which is the required answer in the problem.

2 0 1 1 1
11
9 0 1 0 663
422994
20 1 0 0 998244353
560706529
114514 17723 134 1045 233337
442762986

Hint

Sample Explanation #1

g=[2,1]g=[2,1] (indexed starting from 11).

Let ans=irange(a,b,c)gians=\sum\limits_{i\in \mathrm{range}(a,b,c)} g_i.

When a=1,b=2,c=1a=1,b=2,c=1, ans=2ans=2.

When a=1,b=2,c=2a=1,b=2,c=2, ans=2ans=2.

When a=1,b=3,c=1a=1,b=3,c=1, ans=2+1=3ans=2+1=3.

When a=1,b=3,c=2a=1,b=3,c=2, ans=2ans=2.

When a=2,b=3,c=1a=2,b=3,c=1, ans=1ans=1.

When a=2,b=3,c=2a=2,b=3,c=2, ans=1ans=1.

The answer is ans=2+2+3+2+1+1=11\sum ans=2+2+3+2+1+1=11.

Sample Explanation #2

This sample satisfies Special Property A.

Constraints

For 100%100\% of the testdata: 1n2×1071\leq n\leq 2\times 10^7, 0A,B,C,gn<109+70\leq A,B,C,g_n<10^9 +7.

Test Point ID n=n= Special Property
11 AB
22 10001000 None
33
44 50005000
55
66 10410^4 A
77 10510^5
88 B
99 None
1010 2×1052\times 10^5 A
1111 B
1212 5×1055\times 10^5 None
1313 10610^6 A
1414 B
1515 2×1062\times 10^6 None
1616 3×1063\times 10^6
1717 5×1065\times 10^6 A
1818 10710^7
1919 B
2020 1.3×1071.3\times 10^7 None
2121 1.6×1071.6\times 10^7
2222 2×1072\times 10^7 A
2323 B
2424 None
2525

Special Property A: it is guaranteed that all gig_i are equal.

Special Property B: it is guaranteed that only gn0g_n\neq 0.

Translated by ChatGPT 5