求和=>【链接】
题目相较起_rqy出的要简单很多,来自noip普及组2015
化简这个式子:x+z=2y,故x与z mod 2同余,因此和桶哥的问题——吃桶一样的思路就可以做出来啦qwq:
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int mod=10007; const int maxn=1000010; int n,m,ans,ans1; int c[maxn>>2], c1[maxn>>2], c2[maxn>>2], c3[maxn>>2],c0[maxn>>2],c4[maxn>>2]; int c5[maxn>>2],c6[maxn>>2]; struct jgt{ int a,b; }t[maxn]; int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%d",&t[i].b),t[i].b%=mod; for(int i=1;i<=n;i++) scanf("%d",&t[i].a); for(int i=1;i<=n;i+=2){ c1[t[i].a] = (c1[t[i].a]%mod+c[t[i].a]%mod); c[t[i].a] = (c[t[i].a]%mod+(i%mod)*(t[i].b%mod))%mod; c2[t[i].a] = (c2[t[i].a]%mod+(i%mod)*(c0[t[i].a])%mod)%mod; c0[t[i].a] = (c0[t[i].a]%mod+t[i].b)%mod; c4[t[i].a] = (c4[t[i].a]%mod+c3[t[i].a]%mod*t[i].b%mod)%mod; c3[t[i].a] = c3[t[i].a]%mod+i%mod; c6[t[i].a] = (c6[t[i].a]%mod+t[i].b%mod*c5[t[i].a]%mod*i%mod)%mod; c5[t[i].a] ++; } for(int i=1;i<=m;i++) ans = (ans%mod+c1[i]%mod+c2[i]%mod+c4[i]+c6[i])%mod; memset(c, 0, sizeof(c));memset(c0, 0, sizeof(c0)); memset(c1, 0, sizeof(c1));memset(c2, 0, sizeof(c2)); memset(c4, 0, sizeof(c4));memset(c3, 0, sizeof(c3)); memset(c5, 0, sizeof(c5));memset(c6, 0, sizeof(c6)); for(int i=2;i<=n;i+=2){ c1[t[i].a] = (c1[t[i].a]%mod+c[t[i].a]%mod); c[t[i].a] = (c[t[i].a]%mod+(i%mod)*(t[i].b%mod))%mod; c2[t[i].a] = (c2[t[i].a]%mod+(i%mod)*(c0[t[i].a])%mod)%mod; c0[t[i].a] = (c0[t[i].a]%mod+t[i].b)%mod; c4[t[i].a] = (c4[t[i].a]%mod+c3[t[i].a]%mod*t[i].b%mod)%mod; c3[t[i].a] = c3[t[i].a]%mod+i%mod; c6[t[i].a] = (c6[t[i].a]%mod+t[i].b%mod*c5[t[i].a]%mod*i%mod)%mod; c5[t[i].a] ++; } for(int i=1;i<=m;i++) ans = (ans%mod+c1[i]%mod+c2[i]%mod+c4[i]+c6[i])%mod; printf("%d",(ans+mod)%mod); }
原文:https://www.cnblogs.com/zhuier-xquan/p/10951853.html