E. Intercity Travelling
time limit per test

1.5 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 nn km. Let's say that Moscow is situated at the point with coordinate 00 km, and Saratov — at coordinate nn km.

Driving for a long time may be really difficult. Formally, if Leha has already covered ii kilometers since he stopped to have a rest, he considers the difficulty of covering (i+1)(i+1)-th kilometer as ai+1ai+1. It is guaranteed that for every i∈[1,n−1]i∈[1,n−1] ai≤ai+1ai≤ai+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 11 to n−1n−1 may contain a rest site. When Leha enters a rest site, he may have a rest, and the next kilometer will have difficulty a1a1, the kilometer after it — difficulty a2a2, and so on.

For example, if n=5n=5 and there is a rest site in coordinate 22, the difficulty of journey will be 2a1+2a2+a32a1+2a2+a3: the first kilometer will have difficulty a1a1, the second one — a2a2, then Leha will have a rest, and the third kilometer will have difficulty a1a1, the fourth — a2a2, and the last one — a3a3. Another example: if n=7n=7 and there are rest sites in coordinates 11 and 55, the difficulty of Leha's journey is 3a1+2a2+a3+a43a1+2a2+a3+a4.

Leha doesn't know which integer points contain rest sites. So he has to consider every possible situation. Obviously, there are 2n−12n−1different distributions of rest sites (two distributions are different if there exists some point xx 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 pp — the expected value of difficulty of his journey.

Obviously, p⋅2n−1p⋅2n−1 is an integer number. You have to calculate it modulo 998244353998244353.

Input

The first line contains one number nn (1≤n≤1061≤n≤106) — the distance from Moscow to Saratov.

The second line contains nn integer numbers a1a1, a2a2, ..., anan (1≤a1≤a2≤⋯≤an≤1061≤a1≤a2≤⋯≤an≤106), where aiai is the difficulty of ii-th kilometer after Leha has rested.

Output

Print one number — p⋅2n−1p⋅2n−1, taken modulo 998244353998244353.

Examples
input

Copy
2
1 2
output

Copy
5
input

Copy
4
1 3 3 7
output

Copy
60

理解题意题

  https://www.cnblogs.com/Dillonh/p/9313493.html

公式推导过程 看这个博客

 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = ;
const LL maxn = 1e6 + ;
LL n,ans=,a[maxn],b[maxn];
int main() {
b[]=;
for (int i= ;i<maxn ;i++) b[i]=*b[i-]%mod;
scanf("%lld",&n);
for (int i= ;i<n ;i++) scanf("%lld",&a[i]);
for (int i= ;i<n ;i++)
ans=(ans+a[i]*((b[n--i]+((n-i-)*b[n---i]%mod))%mod)%mod)%mod;
printf("%lld\n",ans);
return ;
}

E. Intercity Travelling的更多相关文章

  1. Codeforces D. Intercity Travelling(区间组合)

    题目描述: D. Intercity Travelling time limit per test 1.5 seconds memory limit per test 256 megabytes in ...

  2. Codeforces 1009 E. Intercity Travelling(计数)

    1009 E. Intercity Travelling 题意:一段路n个点,走i千米有对应的a[i]疲劳值.但是可以选择在除终点外的其余n-1个点休息,则下一个点开始,疲劳值从a[1]开始累加.休息 ...

  3. Educational Codeforces Round 47 (Rated for Div. 2)E.Intercity Travelling

    题目链接 大意:一段旅途长度N,中间可能存在N-1个休息站,连续走k长度时,疲劳值为a1+a2+...+aka_1+a_2+...+a_ka1​+a2​+...+ak​,休息后a1a_1a1​开始计, ...

  4. CF1009E [Intercity Travelling]

    这道题先考虑一种暴力n方做法 设\(f_i\)表示到\(i\)点所有情况的困难度之和(\(f_0=0\)),\(pre_i=\sum_{j=1}^{i} a_j\) 考虑从点\(j\)中途不经过休息站 ...

  5. CodeForces - 1009E Intercity Travelling

    题面在这里! 可以发现全是求和,直接拆开算贡献就好了 #include<bits/stdc++.h> #define ll long long using namespace std; c ...

  6. Educational Codeforces Round 47 (Rated for Div. 2) :E. Intercity Travelling

    题目链接:http://codeforces.com/contest/1009/problem/E 解题心得: 一个比较简单的组合数学,还需要找一些规律,自己把方向想得差不多了但是硬是找不到规律,还是 ...

  7. Intercity Travelling CodeForces - 1009E (组合计数)

    大意: 有一段$n$千米的路, 每一次走$1$千米, 每走完一次可以休息一次, 每连续走$x$次, 消耗$a[1]+...+a[x]$的能量. 休息随机, 求消耗能量的期望$\times 2^{n-1 ...

  8. 1009E Intercity Travelling 【数学期望】

    题目:戳这里 题意:从0走到n,难度分别为a1~an,可以在任何地方休息,每次休息难度将重置为a1开始.求总难度的数学期望. 解题思路: 跟这题很像,利用期望的可加性,我们分析每个位置的状态,不管怎么 ...

  9. Codeforces 1009E Intercity Travelling | 概率与期望

    题目链接 题目大意: 一个人要从$A$地前往$B$地,两地相距$N$千米,$A$地在第$0$千米处,$B$地在第$N$千米处. 从$A$地开始,每隔$1$千米都有$\dfrac{1}{2}$的概率拥有 ...

随机推荐

  1. Python自动化运维——文件与目录差异对比

    Infi-chu: http://www.cnblogs.com/Infi-chu/ 模块:filecmp 安装:Python版本大于等于2.3默认自带 功能:实现文件.目录.遍历子目录的差异 常用方 ...

  2. Python3 利用pip安装BeautifulSoup4模块(Windows版)

    一.找到Python3的安装文件夹 二.将路径复制 三.Windows10 打开Windows PowerShell(管理员).Windows 8.8.1.7使用cmd 切换到相应目录 四.此目录下的 ...

  3. mongodb常用命令学习笔记

    mongodb常用命令学习笔记 创建数据库 use DATABASE_NAME eg: use users; 如果数据库不存在,则创建数据库,否则切换到指定数据库.要显示刚刚创建的数据库,需要向数据库 ...

  4. R语言绘图:时间序列分析 ggplot2绘制ACF PACF

    R语言真是博大精深 方法一 Acf(gold[,2], type = "correlation",lag.max = 100) Acf(gold[,2], type = " ...

  5. python2.7练习小例子(十三)

        13):题目:将一个正整数分解质因数.例如:输入90,打印出90=2*3*3*5.     程序分析:对n进行分解质因数,应先找到一个最小的质数k,然后按下述步骤完成.(1)如果这个质数恰等于 ...

  6. 20145202马超 2016-2017-2 《Java程序设计》第四周学习总结

    20145202马超 2016-2017-2 <Java程序设计>第四周学习总结 教材学习内容总结 继承:打破了封装性 extends 1.提高了代码的复用性. 2.让类与类之间产生了关系 ...

  7. 【jQuery】 js 对象

    [jQuery] js 对象 一.  创建对象的三种方式 <script> var v1 = new Object(); v1.name = "name1"; v1.a ...

  8. Struts2(七.删除和修改用户功能的实现)

    一.删除功能 之前跳转用户列表的时候把用户id,用户名,用户密码存入了ActionContext 1.userlist.jsp <%@ page language="java" ...

  9. Django源码分析之权限系统_擒贼先擒王

    乍见 Django内置的权限系统已经很完善了,加上django-guardian提供的功能,基本上能满足大部分的权限需求.暂且不说django-guardian,我们先来看下Django内置的权限系统 ...

  10. 剑指offer-树的子结构17

    题目描述 输入两棵二叉树A,B,判断B是不是A的子结构.(ps:我们约定空树不是任意一个树的子结构) class Solution: def issubTree(self,pRoot1,pRoot2) ...