较快
2023-08-17 21:24:56
发布于:内蒙古
2阅读
0回复
0点赞
-
- #include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int m,n;
long long ans;
const int p=10007;
struct node{
int num,color,n;
}a[100010];
long long sum[100010][3];//统计相同颜色相同奇偶的格子的数字和
long long cnt[100010][3];//统计k
inline int Read(){
int res=0,ch,flag=0;
if((ch=getchar())=='-')
flag=1;
else if(ch>='0'&&ch<='9')
res=ch-'0';
while((ch=getchar())>='0'&&ch<='9')
res=res10+ch-'0';
return flag?-res:res;
}
inline void Write(int a){
if(a>9)
Write(a/10);
putchar(a%10+'0');
}
int main(){
n=Read();m=Read();
for (int i=1;i<=n;i++){
a[i].num=Read();
a[i].n=i;
}
for (int i=1;i<=n;i++){
a[i].color=Read();
sum[a[i].color][i%2]=sum[a[i].color][i%2]%p+a[i].num%p;
sum[a[i].color][i%2]%=p;
cnt[a[i].color][i%2];
}
for (int i=1;i<=n;i){
if (cnt[a[i].color][i%2]>1){
ans=ans%p+i%p*(a[i].num%p*(cnt[a[i].color][i%2]-2%p)+sum[a[i].color][i%2]%p)%p;//套用推的式子
ans%=p;
}
}
cout<<ans<<endl;
return 0;
}
- #include <cstdio>
这里空空如也
有帮助,赞一个