显示代码纯文本
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
struct point
{
int n,c,s;
}a[100001];
struct pop
{
int l,r;
}b[100001];
int n,i,j,k,ror=1,t,m,ans;
int cmp(const point &p,const point &q)
{
if (p.c==q.c) return p.n<q.n;
else return p.c<q.c;
}
int main()
{
freopen("2015sum.in","r",stdin);
freopen("2015sum.out","w",stdout);
scanf("%d%d",&n,&m);
for (i=1; i<=n; ++i)
{
scanf("%d",&a[i].s);
a[i].n=i;
}
for (i=1; i<=n; ++i) scanf("%d",&a[i].c);
sort(a+1,a+n+1,cmp);
while (ror<=n)
{
t++;
b[t].l=ror;
while (a[ror+1].c==a[ror].c) ror++;
b[t].r=ror;
ror++;
}
//for (i=1; i<=n; ++i) printf("%d %d %d\n",a[i].c,a[i].s,a[i].n);
//for (i=1; i<=t; ++i) printf("%d %d\n",b[i].l,b[i].r);
for (i=1; i<=t; ++i)
for (j=b[i].l; j<b[i].r; ++j)
for (k=j+1; k<=b[i].r; ++k)
if ((a[j].n+a[k].n)%2==0)
ans=(ans+((a[j].n+a[k].n)%10007)*((a[j].s+a[k].s)%10007))%10007;
printf("%d\n",ans);
return 0;
}