列表

详情


NC206678. PairComplex

描述

Given nonnegetive interger sequences a,b of length n .

Let



You need to calculate

输入描述

The first line of the input contains a single interger number n  .

The second line of the input contains n interger numbers , which are separated by spaces.

The third line of the input contains n interger numbers , which are separated by spaces.

输出描述

Print a single interger number ans .

示例1

输入:

2
1 2
2 1

输出:

9

原站题解

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

C++14(g++5.4) 解法, 执行用时: 296ms, 内存消耗: 23764K, 提交时间: 2020-06-13 16:45:38

#include<bits/stdc++.h>
#define ll long long
const ll tt=998244353;
int n;
ll ans=0,a[1000005],b[1000005],s[1000005];
int main(){
	int i;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	for (i=1;i<=n;i++) scanf("%d",&b[i]);
	for (i=n;i;i--) s[i]=(s[i+1]+b[i]*(n-i+1)%tt)%tt;
	for (i=1;i<=n;i++) ans=(ans+i*a[i]%tt*s[i]%tt)%tt;
	printf("%lld",ans);
	return 0;
}

C++11(clang++ 3.9) 解法, 执行用时: 423ms, 内存消耗: 23904K, 提交时间: 2020-06-13 14:55:33

#include<bits/stdc++.h>
using namespace std;
#define N 1000010
#define LL long long
#define MOD 998244353
LL n,a[N],b[N],s[N],ans;
int main()
{
	scanf("%lld",&n);
	for(LL i=1;i<=n;i++)
	  scanf("%lld",&a[i]),s[i]=(i*a[i]+s[i-1])%MOD;
	for(LL i=1;i<=n;i++)
	  scanf("%lld",&b[i]),ans=(ans+s[i]*b[i]%MOD*(n-i+1))%MOD;
	printf("%lld\n",ans);
}

上一题