305332: CF1009E. Intercity Travelling

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Intercity Travelling

题意翻译

## 题目描述 你要从A到B,需要走 $n$ 步。若你已走了 $s$ 步,那么你再走一步的代价将为 $a[s+1]$ 。 途中有 $n$ 个休息站,休息后 $s$ 将变为 $0$ 。 求出你从A到B的代价的期望 $p$ 乘上 $2^{n-1}$ 对 $998244353$ 取模的结果。 ## 输入输出格式 ### 输入格式 第一行是 $n$ 。 第二行有 $n$ 个整数,第i个整数为 $a[i]$ 。 ### 输出格式 一行,为 $p\times 2^{n-1}\ mod\ 998244353$ 。 ## 附:样例解释 ### 样例一 有2种可能的代价分别为`1 2`和`1 1`,期望为2.5,答案为5。 ### 样例二 有8种可能的代价分别为`1 3 3 7`、`1 1 3 3`、`1 3 1 3`、`1 1 1 3`、`1 3 3 1`、`1 1 3 1`、`1 3 1 1`、`1 1 1 1`,期望为7.5,答案为60。 感谢@M_sea 提供的翻译

题目描述

Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car. The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but in this problem we will consider it to be straight), and the distance between Moscow and Saratov is $ n $ km. Let's say that Moscow is situated at the point with coordinate $ 0 $ km, and Saratov — at coordinate $ n $ km. Driving for a long time may be really difficult. Formally, if Leha has already covered $ i $ kilometers since he stopped to have a rest, he considers the difficulty of covering $ (i + 1) $ -th kilometer as $ a_{i + 1} $ . It is guaranteed that for every $ i \in [1, n - 1] $ $ a_i \le a_{i + 1} $ . The difficulty of the journey is denoted as the sum of difficulties of each kilometer in the journey. Fortunately, there may be some rest sites between Moscow and Saratov. Every integer point from $ 1 $ to $ n - 1 $ may contain a rest site. When Leha enters a rest site, he may have a rest, and the next kilometer will have difficulty $ a_1 $ , the kilometer after it — difficulty $ a_2 $ , and so on. For example, if $ n = 5 $ and there is a rest site in coordinate $ 2 $ , the difficulty of journey will be $ 2a_1 + 2a_2 + a_3 $ : the first kilometer will have difficulty $ a_1 $ , the second one — $ a_2 $ , then Leha will have a rest, and the third kilometer will have difficulty $ a_1 $ , the fourth — $ a_2 $ , and the last one — $ a_3 $ . Another example: if $ n = 7 $ and there are rest sites in coordinates $ 1 $ and $ 5 $ , the difficulty of Leha's journey is $ 3a_1 + 2a_2 + a_3 + a_4 $ . Leha doesn't know which integer points contain rest sites. So he has to consider every possible situation. Obviously, there are $ 2^{n - 1} $ different distributions of rest sites (two distributions are different if there exists some point $ x $ such that it contains a rest site in exactly one of these distributions). Leha considers all these distributions to be equiprobable. He wants to calculate $ p $ — the expected value of difficulty of his journey. Obviously, $ p \cdot 2^{n - 1} $ is an integer number. You have to calculate it modulo $ 998244353 $ .

输入输出格式

输入格式


The first line contains one number $ n $ ( $ 1 \le n \le 10^6 $ ) — the distance from Moscow to Saratov. The second line contains $ n $ integer numbers $ a_1 $ , $ a_2 $ , ..., $ a_n $ ( $ 1 \le a_1 \le a_2 \le \dots \le a_n \le 10^6 $ ), where $ a_i $ is the difficulty of $ i $ -th kilometer after Leha has rested.

输出格式


Print one number — $ p \cdot 2^{n - 1} $ , taken modulo $ 998244353 $ .

输入输出样例

输入样例 #1

2
1 2

输出样例 #1

5

输入样例 #2

4
1 3 3 7

输出样例 #2

60

Input

题意翻译

## 题目描述 你要从A到B,需要走 $n$ 步。若你已走了 $s$ 步,那么你再走一步的代价将为 $a[s+1]$ 。 途中有 $n$ 个休息站,休息后 $s$ 将变为 $0$ 。 求出你从A到B的代价的期望 $p$ 乘上 $2^{n-1}$ 对 $998244353$ 取模的结果。 ## 输入输出格式 ### 输入格式 第一行是 $n$ 。 第二行有 $n$ 个整数,第i个整数为 $a[i]$ 。 ### 输出格式 一行,为 $p\times 2^{n-1}\ mod\ 998244353$ 。 ## 附:样例解释 ### 样例一 有2种可能的代价分别为`1 2`和`1 1`,期望为2.5,答案为5。 ### 样例二 有8种可能的代价分别为`1 3 3 7`、`1 1 3 3`、`1 3 1 3`、`1 1 1 3`、`1 3 3 1`、`1 1 3 1`、`1 3 1 1`、`1 1 1 1`,期望为7.5,答案为60。 感谢@M_sea 提供的翻译

加入题单

上一题 下一题 算法标签: