列表

详情


NC15839. Max Convolution

描述

Alice has an array , she want to calculate the other array where

Can you help her? For simplicity, please output

输入描述

In the first line there are two integer n, m,(1 <= n <= 100000, 1 <= m <= 1000000000).
In the second line there are n integers .

输出描述

Output a single integer, which is

示例1

输入:

5 2
1 10 6 10 8

输出:

4985

说明:

b_0 = a_0\cdot a_0 = 1
b_1 = a_0\cdot a_1 + a_1\cdot a_0 + a_1\cdot a_1= 120
b_2 = a_0\cdot a_2 + a_1\cdot a_2 + a_2\cdot a_0 + a_2\cdot a_1 + a_2\cdot a_2 = 168
b_3 = a_0\cdot a_3 + a_1\cdot a_3 + a_2\cdot a_3 + a_3\cdot a_0 + a_3\cdot a_1 + a_3\cdot a_2 + a_3\cdot a_3 = 440
b_4 = a_0\cdot a_4 + a_1\cdot a_4 + a_2\cdot a_4 + a_3\cdot a_4 + a_4\cdot a_0 + a_4\cdot a_1 + a_4\cdot a_2 + a_4\cdot a_3 + a_4\cdot a_4 = 496
ans = 1\cdot b_0 + 2\cdot b_1 + 3\cdot b_2 + 4\cdot b_3 + 5\cdot b_4 = 4985

示例2

输入:

10 3
83254494 79256570 664815211 929105503 348307749 129917295 141270181 116122929 432020021 461745049

输出:

964655557

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 65ms, 内存消耗: 1512K, 提交时间: 2019-02-14 22:09:20

#include<stdio.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
const int p=1e9+7;
int n,m,a[110000];
long long b[110000],ans;
inline long long qpow(long long a,int n){
	long long ans=1;
	while (n){
		if (n&1) ans=ans*a%p;
		a=a*a%p;
		n>>=1;
	}
	return ans;
	
}
int main(){
	scanf("%d%d",&n,&m);
	fo(i,1,n){
		scanf("%d",&a[i]);
		a[i]+=a[i-1];
		if (a[i]>=p) a[i]-=p;
		b[i]=qpow(a[i],m)-qpow(a[i-1],m);
		if (b[i]<0) b[i]+=p;
		ans+=i*b[i]%p;
	}
	ans%=p;
	printf("%lld\n",ans);
	return 0;
}

C++11(clang++ 3.9) 解法, 执行用时: 60ms, 内存消耗: 2916K, 提交时间: 2020-09-25 23:16:46

#include<iostream>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll va[100005],su[100005]={0};
ll poww(ll x,ll n){
    ll ans=1;
    while(n){
        if(n&1) ans=ans*x%mod;
        x=x*x%mod;n>>=1;
    }return ans;
}
int main(){
    ll n,m,ans=0;cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>va[i],su[i]=(va[i]+su[i-1])%mod;
    for(int i=1;i<=n;i++)
        ans+=((poww(su[i],m)-poww(su[i-1],m)+mod)%mod*i)%mod,ans=ans%mod;
    cout<<ans;
}

上一题