[BZOJ3823] [East! Simulation competition _ Round5T1: sentiment message push formula + linear screening inverse element (simplified comparison of the public method), bzoj3823_round5t1

Source: Internet
Author: User

[BZOJ3823] [East! Simulation competition _ Round5T1: sentiment message push formula + linear screening inverse element (simplified comparison of the public method), bzoj3823_round5t1

Question 1:

We define a point as a zero-dimensional element, a line as a one-dimensional element, and a plane as a two-dimensional element ......

Since a low-dimensional supercube is translated on the corresponding new axis to obtain a high-dimensional supercube, for example, a two-dimensional supercube is a plane, and then expands along the new Z axis, then a low-dimensional element will increase the one-dimensional element into a high-dimensional element, such as the point to the line, line to the surface, and surface to the body ......

In this way, there is a push type:

High-dimensional elements are derived from the first dimension, and are replicated and retained by the same dimension elements,

That is to say, after a cube is dimension-increasing, the number of I-dimensional elements of the high-dimensional supercube will be the number of I-dimensional elements of the original supercube * 2 + (I-1.


Then, a formula for the combined number can be obtained through the derivation/collision calculation of the ghost animals,

Finally, add a linear screening inverse element, and pay attention to the memory.


Question 2:

Starting from the relationship between the degrees of elements, there is a rule:

The number of X-1 dimension elements corresponding to an x Dimension Element is fixed, for example, a line is always two points, a surface is always four points ...... The I Dimension Element corresponds to 2i (I-1) dimension elements. The number of x + 1 dimension elements corresponding to the x dimension increases with the increase of dimensions. For example, the two-dimensional supercube has a point and two lines, and the three-dimensional cube has 1.3 lines, that is:

An x-Dimension Element corresponds to (y-x) (x + 1) dimension elements in y-dimension.

Then, based on the doubling of the number of points, we can get the number of zero-dimensional elements (points) of the cube, and then export the number of higher-dimensional elements according to the formula, in this way, the O (n) solution can be obtained. However, due to various modulo operations, a linear screening inverse element is required ~~

This is my method, but unfortunately ...... The fast power long is written as int !!!!! Weak.


Code:

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 10001000using namespace std;int n,p;long long A[2];long long inv[N];long long power(long long x,int k){long long ans=1;while(k){if(k&1)ans*=x,ans%=p;x*=x,x%=p;k>>=1;}return ans;}void getinv(int x){inv[1]=1;for(int i=2;i<=x;i++)inv[i]=(long long)(p-p/i)*inv[p%i]%p;}int now,last;int main(){int i,j,k;scanf("%d%d",&n,&p);now=0,last=1;A[0]=power(2,n);getinv(n);long long ans=A[0];for(i=1;i<=n;i++){now^=1,last^=1;A[now]=A[last]*(n-i+1)%p*inv[i]%p*inv[2]%p;ans^=A[now];}cout<<ans<<endl;fclose(stdin);fclose(stdout);return 0;}


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.