#10127. 「一本通 4.3 练习 1」最大数

Archie

线段树精简版

没有lazy,没有pushdown

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define int long long
using namespace std;
const int maxn=1e6+5;
int sum[maxn][2];
int num[maxn];
int col[maxn];
int cnt[maxn][2];
int ans;
const int mod=10007;
int n,m;
signed main(){
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;++i){
		scanf("%lld",&num[i]);
		num[i]%=mod;
	}
	for(int i=1;i<=n;++i){
		scanf("%lld",&col[i]);
		sum[col[i]][i%2]+=num[i]%mod;
		sum[col[i]][i%2]%=mod;
		cnt[col[i]][i%2]+=1;
		cnt[col[i]][i%2]%=mod;
	}
	for(int i=1;i<=n;++i){
		if(cnt[col[i]][i%2]>1){
		ans+=(i%mod*num[i]%mod*((cnt[col[i]][i%2]-1)%mod)+i%mod*((sum[col[i]][i%2]-num[i])%mod)%mod)%mod;
		ans%=mod;
		}
	}
	cout<<ans%mod;
	return 0;
} 
posted @ 2021-07-19 20:57  Simex  阅读(59)  评论(0编辑  收藏  举报