2020-08-16 求和

2020-08-16  本文已影响0人  JalorOo

https://www.luogu.com.cn/problem/P2671

#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstring>
using namespace std;

long long qmi(int m, int k)
{
    int res = 1, t = m;
    while (k)
    {
        if (k&1) res = res * t;
        t = t * t;
        k >>= 1;
    }
    return res;
}

int read(){
    int x = 0,f = 1;
    char c = getchar();
    while (c<'0'||c>'9') {
        if (c=='-') {
            f = -1;
        }
        c = getchar();
    }
    while (c>='0'&&c<='9') {
        x = x*10+c-'0';
        c = getchar();
    }
    return x*f;
}


int s[100005][2],sum[100005][2],c[100005],x[100005];//定义二维数组方便分组
int n,m,ans;
int main(){
    scanf ("%d %d",&n,&m);//其实m没有什么用处
    for (int i=1;i<=n;i++){
        scanf ("%d",&x[i]);
    }
    for (int i=1;i<=n;i++){
        scanf ("%d",&c[i]);
        s[c[i]][i%2]++;//求出这个分组中有多少个数
        sum[c[i]][i%2]=(sum[c[i]][i%2]+x[i])%10007;//事先求出累加和,注意,要mod10007
    }
    for (int i=1;i<=n;i++){
        ans=(ans+i*((s[c[i]][i%2]-2)*x[i]%10007+sum[c[i]][i%2]))%10007;//依次然后代入,注意,也要mod10007
    }
    printf ("%d\n",ans);//最后输出
    return 0;
}
/*
6 2
5 5 3 2 2 2
2 2 1 1 2 1
============
82
*/
上一篇下一篇

猜你喜欢

热点阅读