0%

Problem 663


Problem 663


Sums of subarrays

Let tk be the tribonacci numbers defined as:
t0=t1=0;
t2=1;
tk=tk1+tk2+tk3 for k3.

For a given integer n, let An be an array of length n (indexed from 0 to n1), that is initially filled with zeros.
The array is changed iteratively by replacing An[(t2i2 mod n)] with An[(t2i2 mod n)]+2(t2i1 mod n)n+1 in each step i.
After each step i, define Mn(i) to be maxj=pqAn[j]:0pq<n, the maximal sum of any contiguous subarray of An.

The first 6 steps for n=5 are illustrated below:
Initial state: ,A5=0,0,0,0,0
Step 1: A5=4,0,0,0,0 , M5(1)=0
Step 2: A5=4,2,0,0,0 , M5(2)=0
Step 3: A5=4,2,4,0,0 , M5(3)=4
Step 4: A5=4,2,6,0,0 , M5(4)=6
Step 5: A5=4,2,6,0,4 , M5(5)=10
Step 6: A5=4,2,6,0,4 , M5(6)=12

Let S(n,l)=i=1lMn(i). Thus S(5,6)=32.
You are given S(5,100)=2416, S(14,100)=3881 and S(107,1000)=1618572.

Find S(10,000,003,10,200,000)S(10,000,003,10,000,000).


子数组之和

tk为如下定义的三阶斐波那契数列
t0=t1=0
t2=1
tk=tk1+tk2+tk3对于任意k3

对于给定整数n,记An为长为n的数组(数组下标为0n1),数组中的元素初始值均设为0。
接着对数组进行初步调整,在第i步,将An[(t2i2modn)]替换为An[(t2i2modn)]+2(t2i1modn)n+1
在第i步替换后,记Mn(i)maxj=pqAn[j]:0pq<n,即An所有连续子数组之和的最大值。

n=5时,前6步调整过程如下所示:
初始状态:,A5=0,0,0,0,0
1步:A5=4,0,0,0,0M5(1)=0
2步:A5=4,2,0,0,0M5(2)=0
3步:A5=4,2,4,0,0M5(3)=4
4步:A5=4,2,6,0,0M5(4)=6
5步:A5=4,2,6,0,4M5(5)=10
6步:A5=4,2,6,0,4M5(6)=12

S(n,l)=i=1lMn(i),因此S(5,6)=32
已知S(5,100)=2416S(14,100)=3881S(107,1000)=1618572

S(10,000,003,10,200,000)S(10,000,003,10,000,000)


Gitalking ...