2020hdu多校第六场1001

#include <iostream>
#include <cstdio>      //定义输入/输出函数
#include <stack>      //STL 堆栈容器
#include <map>       //STL 映射容器
#include<set>
#include <vector>     //STL 动态数组容器
#include <string>     //字符串类
#include <iterator>        //STL迭代器
#include <cstdlib>     //定义杂项函数及内存分配函数
#include <cstring>     //字符串处理ed
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<fstream>
#include<ctime>
using namespace std;
#define ll long long
#define ull unsigned long long
#define FOR(ITER,BEGIN,END)  for(int  ITER=BEGIN;ITER<END;ITER++)
#define PER(ITER,TIMES) FOR(ITER,0,TIMES)
#define TIME(TIME_NUMBER) PER(_PETER_MRSCO_ITER_,TIME_NUMBER)
#define close_stdin ios::sync_with_stdio(false)
#define inf 0x3f3f3f3f
#define llm 1e16
#define out_put(l,r,aaaa) {for (int i=l;i<=r;i++){cout<<aaaa[i]<<" ";}cout<<"\n";}
const int maxn = 200005;
ll iv[maxn];
const ll mod = 1000000007;
ll sum[maxn];
int n;
ll a[maxn];
// 用于预处理 中 维护一个  inv[maxn] 复杂度只有O(n)极其好用
void presolve() {
    iv[1] = 1;
    for (ll i = 2;i <= 2e5+1;i++) { iv[i] = iv[mod % i] * (mod - mod / i) % mod; }
    sum[1] = iv[1] ;
    sum[0] = 0;
    for (int i = 2;i <= 2e5+1;i++) { sum[i] = (sum[i - 1] +  iv[i] ) % mod; }
}
void solve() {
    cin >> n;
    for (int i = 1;i <= n;i++) { cin >> a[i]; }
    ll ans = 0;
    ll s = 0;
    for (int i = 1;i <= (n + 1) / 2;i++) {
        int j = (n + 1 - i);
        s = ((sum[j] - sum[i - 1]+mod)%mod+s)%mod;
        if (i == j) { ans = (ans + (a[i]) * (s) % mod) % mod; }
        else { ans = (ans + (a[i] + a[j]) * (s) % mod) % mod; }
    }
    ans = 2 * ans * iv[n]%mod * iv[n + 1]%mod;
    cout << ans << "\n";

}
int main() {
    close_stdin;
    cin.tie(0);
    cout.tie(0);
    presolve();
    int t;
    cin >> t;
    //cout << (25 * iv[12]) % mod;
    while (t--) {
        solve();
    }
}
全部评论

相关推荐

点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务