小红的数组权值【Python实现】

def solve():
    MOD = 10**9 + 7

    n = int(input().strip())
    a = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        # i 是 0-based,下标转成 1-based
        idx = i + 1
        cnt_right = n - i
        coef = idx * (idx + 1) // 2
        ans = (ans + a[i] * cnt_right % MOD * coef) % MOD

    print(ans)


if __name__ == "__main__":
    solve()

小红的数组权值【Python实现】

© 版权声明

相关文章

暂无评论

none
暂无评论...