zoukankan      html  css  js  c++  java
  • E. Intercity Travelling

    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,n1]i∈[1,n−1] aiai+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 n1n−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 2n12n−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, p2n1p⋅2n−1 is an integer number. You have to calculate it modulo 998244353998244353.

    Input

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

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

    Output

    Print one number — p2n1p⋅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

    公式推导过程 看这个博客

      

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 const int mod = 998244353;
     5 const LL maxn = 1e6 + 7;
     6 LL n,ans=0,a[maxn],b[maxn];
     7 int main() {
     8     b[0]=1;
     9     for (int i=1 ;i<maxn ;i++) b[i]=2*b[i-1]%mod;
    10     scanf("%lld",&n);
    11     for (int i=0 ;i<n ;i++) scanf("%lld",&a[i]);
    12     for (int i=0 ;i<n ;i++)
    13         ans=(ans+a[i]*((b[n-1-i]+((n-i-1)*b[n-1-1-i]%mod))%mod)%mod)%mod;
    14     printf("%lld
    ",ans);
    15     return 0;
    16 }
  • 相关阅读:
    (转)怎样获得与激活Windows 7超级管理员权限
    (转) C代码优化方案
    英语词汇立体记忆 02
    (转)LUA和C之间的函数调用
    通过lua自带例子学习lua 01
    英语词汇立体记忆 01
    反射(类加载内存分析)
    反射(类加载器的作用)
    反射(动态创建对象操作属性)
    反射(分析类初始化)
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/9315288.html
Copyright © 2011-2022 走看看