noip2016 exercises (section 2)

#include<cstdio>//2016noip练习题,2,区间;
#include<iostream>
using namespace std;
typedef long long LL;
const int maxn=20000005;
int n,k,P,A,B,C,D;
int s[maxn],f[maxn],g[maxn];
int ans;

int main()
{
 freopen("range.in","r",stdin);
 freopen("range.out","w",stdout);
 scanf("%d%d%d%d%d%d%d",&n,&k,&P,&A,&B,&C,&D);
 s[1]=A;
 for(int i=2;i<=n;i++)
  s[i]=((LL)s[i-1]*B+C)%D;
 for(int i=1;i<=n;i++)
  if((i-1)%k==0)
   f[i]=s[i];   //f数组记录区间前缀和
  else
   f[i]=(LL)f[i-1]*s[i]%P;//当不是整区间时,记录前部分乘积;
 g[n+1]=1;
 for(int i=n;i;i--)
  if(i%k==0)
   g[i]=s[i];//g数组记录后缀和
  else
   g[i]=(LL)g[i+1]*s[i]%P;
 for(int i=1;i+k-1<=n;i++)
  if((i-1)%k==0)
   ans^=g[i];@ When the time interval exactly, and a suffix that is the product of    ANS ^ = (LL) F [K-I +. 1] * G [I]% P; // if not for the whole range that the product of the product as a prefix × suffix plot
  the else

 printf("%d\n",ans);
 return 0;
}

Published 20 original articles · won praise 1 · views 6338

Guess you like

Origin blog.csdn.net/yichengchangan/article/details/54896829