[Explanations] Luo Gu p3909 [the product of] XOR

Foreword

This question I was looking to find the law.

Certify as follows:

First, we enumerate (a [1] * a [2]) formula begins:

a[1]a[2]a[3]+a[1]a[2]a[4]+...+a[1]a[2]a[n].

Then extracted (a [1] * a [2]), can be obtained:

(a[1]a[2])(a[3]+a[4]+...+a[n]).

So we use a prefix and an array of maintenance at f, f [i] represents the number before i and.

for(int i=1;i<=n;i++){
    f[i]=f[i-1]+a[i];
}

So the equation becomes:

(a[1]a[2])(f[n]-f[2])

Similarly, we can obtain (a [1] * a [3]) begins formula:

(a[1]a[3])(f[n]-f[3])

Therefore, in equation a [1] is started:

a[1](a[2](f[n]-f[2])+a[3](f[n]-f[3])+...+a[n](f[n]-f[n]))

To get in parentheses:

a[1](a[2]f[n]+ a[3]f[n]+ ...+ a[n]f[n]- a[2]f[2]- a[3]f[3]- ...- a[n]*f[n])

Extracting a f [n] can be obtained:

a[1](f[n](a[2]+a[3]+...+a[n])-a[2]f[2]-a[3]f[3]-...-a[n]*f[n])

Then we define an array c, c [i] denotes the i-th former (a [i] * f [i]) and.

for(int i=1;i<=n;i++){
    c[i]=c[i-1]+(a[i]*f[i]);
}

So the formula has become:

a[1](f[n](f[n]-f[1])-(c[n]-c[1]))

Then we can derive equation by a [1] Examples:

year = years + (a [i] (f [i] (f [n] -f [i]) - (c [n] -c [i]));

We can then O (n) to enumerate the results obtained.

supplement

Remember to open long long, then before the first increase mod% mod, (in fact, some solution to a problem without adding mod, but

I will not add WA, I am more likely it is weak)

Here conferred on the Code (WA several times because so crazy%, slightly ugly Wuguai):

#include<bits/stdc++.h>
#define N 1000005
const long long p=1e9+7;
using namespace std;
long long n,ans,a[N],f[N],c[N];
inline long long read(){
  long long r=0,t=1,c=getchar();
  while(c<'0'||c>'9'){
    t=c=='-'?-1:1;
    c=getchar();
  }
  while(c>='0'&&c<='9'){
    r=r*10+c-48;
    c=getchar();
  }
  return r*t;
}//快读
int main(){
  n=read();
  for(int i=1;i<=n;i++)
    a[i]=(read()+p)%p,f[i]=((f[i-1]+a[i])+p)%p;
  for(int i=1;i<=n;i++)
    c[i]=((c[i-1]+((f[i]*a[i])+p)%p+p)%p+p)%p;
  for(int i=1;i<=n-2;i++){
    ans=((ans+(((a[i]+p)%p)*((((((f[n]-f[i])+p)%p)*(f[n]%p))%p)-(((c[n]-c[i])+p)%p+p)%p))%p)+p)%p;
  }
  ans=((ans*6)+p)%p;
  printf("%lld",(ans+p)%p);
  return 0;
}

 洛谷博 off

Guess you like

Origin www.cnblogs.com/Biscuits0819/p/Biscuits_0819_lgyhzj.html