[P2671][NOIP2015]求和 (数论)
这位大神讲得很详细:点我
本蒟蒻只会抄抄题解了
#include<bits/stdc++.h> #define max(a,b) (a>b?a:b) #define min(a,b) (a<b?a:b) #define ll long long #define N 100005 #define mod 10007 #define inc(a,b) (a=(a+b)%mod) using namespace std; inline int read() { int f = 1, x = 0; char ch; do { ch = getchar(); if (ch == '-')f = -1; } while (ch<'0' || ch>'9'); do { x = x * 10 + ch - '0'; ch = getchar(); } while (ch >= '0'&&ch <= '9'); return f * x; } int a[N],c[N],f[2][N],d[2][N]; int ans; int main() { #ifdef onlinejudge freopen("sum.in","r",stdin); freopen("sum.out","w",stdout); #endif int n=read(),m=read(); for(int i=1;i<=n;i++) a[i]=read()%mod; for(int i=1;i<=n;i++) { c[i]=read(); inc(f[i%2][c[i]],a[i]); inc(d[i%2][c[i]],1); } for(int i=1;i<=n;i++) inc(ans,(i%mod * ((f[i%2][c[i]]+(d[i%2][c[i]]-2)%mod*a[i]+mod)%mod))); cout<<ans; }