线段树精简版
没有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;
}