P3909 the product of a difference or difference

Source: Internet
Author: User

P3909 the product of a difference or difference

Why is it called the product of XOR?
Answer: As long as it's not about Alice and Bob.

Finish this water problem, feel oneself weak explode.
In the beginning, we should consider the optimization of violence \ (O (n^3) \) .
And then noticed the question of \ (6\) why not ⑨
Then I thought of the whole arrangement, and then I made a wave out of the whole line.
As follows:

Notice \ (a_i*a_j*a_k=a_j*a_k*a_i\), and then three elements of the full array is 6
Then the test instructions is transformed from a pile of numbers, not duplicated, not omitted to select three elements, to find out the product of all triples and
How to achieve it?
At first it was the violence of \ (O (n^3) \)
Then found that the prefix and the idea can be used to calculate the product of the next two number, in the prefix and a bit. Then in the \ (O (N) \) enumeration of the first number, take advantage of the prefix and calculate the and
You can then use a similar idea to turn that \ (o (n^2) \) preprocessing into a \ (o (N) \) .

But

I tuned for a long time, still no Gan out.
And then look at the code of the others. Found
We just have to deal with three prefixes and just do it.

The code is as follows

#include<cstdio>#include<algorithm>#include<iostream>const int maxn=1000010;const long long mod=1e9+7;int s[maxn];int S[maxn];int main(){    int n;    scanf("%d",&n);    long long pas;    long long ans=0;    for(int i=1;i<=n;i++)    {        scanf("%lld",&pas);        s[i]=(s[i-1]+pas)%mod;        S[i]=(S[i-1]+pas*s[i-1])%mod;        ans=(ans+pas*S[i-1])%mod;    }    pas=ans;    for(int i=1;i<=5;i++)        ans=(ans+pas)%mod;    printf("%lld",ans);}

Really is pure not affectation. Vomiting Blood Emmm

Found himself a wave of seemingly positive things, was defeated by a wave of code skills.
Sad

P3909 the product of a difference or difference

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.