【(抄的)题解】P5686 [CSP-SJX2019]和积和

#include<map>
#include<queue>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#define ll long long
#define mod 1000000007
using namespace std;
int n, a[500010], b[500010];
ll suma,sumb,sumaxb;
ll ans;

int read(){
	char c;int fl = 1;
	c = getchar();
	while(c < '0' || c > '9'){
		if(c == '-')	fl=-1;
		c = getchar();
	}
	int num = 0;
	while(c >= '0' && c <= '9'){
		num *= 10; num += int(c - '0');
		c = getchar();
	}
	return num * fl;
}
int main(){
	n = read();
	for(int i = 1; i <= n; i++)	a[i] = read();
	for(int i = 1; i <= n; i++)	b[i] = read();
	for(int i=1;i<=n;i++){
		suma+=a[i];suma%=mod;
		sumb+=b[i];sumb%=mod;
		sumaxb+=1ll*a[i]*b[i];sumaxb%=mod;
		a[i+1]+=a[i];a[i+1]%=mod;
		b[i+1]+=b[i];b[i+1]%=mod;
	}
	ans = (n+1) * sumaxb - suma*sumb;
	ans %= mod;
	ans += mod;
	ans %= mod;
	printf("%lld\n", ans);
	return 0;
}
posted @ 2020-10-15 17:42  _Buffett  阅读(135)  评论(2编辑  收藏  举报