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. linux文件操作篇 (四) 目录操作

    #include <sys/stat.h>#include <unistd.h>#include <dirent.h> //创建文件夹 路径 掩码 int mkdi ...

  2. ffmpeg使用笔记

    1.从mp4中提取h264:ffmpeg -i 264.mp4 -codec copy -bsf h264_mp4toannexb -f h264 output.h2642.从mp4中提取hevc:f ...

  3. linux ln 建立软链接-- 基于dubbo-zookeeper服务的 服务jar 引用公共的 lib

    对于ln命令网上有很多的教程,这里不再复述, 其基本目的是:多个文件夹公用一个文件夹的里的文件. 其基本命令格式: ln [option] source_file dist_file (source_ ...

  4. 【转】让Moodle支持多个域名

    默认情况下,moodle仅能绑定一个域名.但是由于学校网络分内网和外网,总希望如果是外网访问的,用外网的域名,用内网访问的,就转到内网的ip.这样访问的速度会更快一些,也减低对防火墙的压力.尤其是当外 ...

  5. P2212 [USACO14MAR]浇地Watering the Fields

    P2212 [USACO14MAR]浇地Watering the Fields 题目描述 Due to a lack of rain, Farmer John wants to build an ir ...

  6. Fiddler 发送post 请求失败

    今天服务端同事,让我发一个post 请求.然后呢,一直有问题.告诉我签名失败. 后来换了其他的在线模拟post,都是可以的. 后来找到原因了, post 请求,必须要有Content-Type 和 C ...

  7. 使用USB Key(加密狗)实现身份认证

    首先你需要去买一个加密狗设备,加密狗是外形酷似U盘的一种硬件设备! 这里我使用的坚石诚信公司的ET99产品 公司项目需要实现一个功能,就是客户使用加密狗登录, 客户不想输入任何密码之类的东西,只需要插 ...

  8. Apache 服务器性能评估

    1 查看当前并发连接数 netstat -an | grep ESTABLISHED | wc -l 2 查看当前进程数 ps aux|grep httpd|wc -l

  9. 玩转Vim-札记(二)

    玩转Vim-札记(二) 距上篇博文已有一周有余,上次主要介绍了编辑器之神Vim的起源.安装并介绍了两种模式以及一些简单的操作.本次将继续对Vim的使用进行介绍. 登堂入室 首先接着说移动吧: 0 → ...

  10. react children技巧总结

    在使用该技巧时,建议先看一下相关的知识,点我查看 假如使用该属性时,想把父组件的所有属性及部分方法传递给子组件,该怎么办呢?看代码 const Child = ({ doSomething, valu ...