[Los] -19-11-3 Valley Race month basis div2 Game Exercises

Transformed the meaning of problems

Requirements meaning of the questions beg \ ([l, r] \ ) in (a [l] -1 \) \ if you can win the upper hand in the case, transforming it, in fact, that Italy can also be understood as follows: The first step must take the upper hand \ (L \) , whether FLAC win.

Backward Game

Category talk, find out the nature.

Paint backstepping less, at a right end point is determined, it is obvious that the following properties.

  1. The first point to right point r person, if wins the right end point of an odd number, an even number is lost.

  2. If the first to \ (I \) who win point, the first to \ ([im, i-1 ] \) of the person will lose.

  3. Assuming that the first to the \ (I \) human point called the point of losing losing points, in addition to the right end point of the link to lose point range, the other section will lose points contain at least consecutive \ (m \) th You will lose points.

  4. According \ (2 \) article can be obtained, if the \ (i + 1 \) dots is losing points, the interval \ ([i + 1, min (i + m, r)] \) are losing point, the right end point is equivalent to \ (I \) at a point , this time to a first \ (I \) point status and outcome of human \ (1 \) like article.

According to the above properties, the following properties are summarized:

Right point \ (R & lt \) in the case where, when the \ (R & lt \) dot is losing point, the outcome of the foregoing state may be equivalent to \ (r-1 \) point as a right end point, if \ (R & lt \) point win points, may be the \ (rm-1 \) is the equivalent point as the right point.

So, we now need to look for \ (r \) point is, \ (L \) point whether it is \ (r \) points to win the point, it can also be seen as \ (r \) is equivalent to the left post , \ (L \) is not new \ (R & lt \) of win points, equivalent to the left \ (R & lt \) there are two cases. One is a mobile \ (R & lt \) until \ (R & lt \) is not greater than \ (L \) , may fall just \ (L \) the point where it can \ (L \) if an odd number is determined whether a win point, another mobile \ (R & lt \) until \ (R & lt \) is not greater than \ (L \) , and then found \ (L \) point can not be regarded as equivalent to the right end (not fall \ (L \) ). In the first case, \ (L \) whether a win point \ (a [l] \) is determined even is odd, the second case, the \ (L \) must not be used as win points.

So how quickly determine \ (l \) whether it is \ (r \) win the point? I can record pr [i] i represents a point right point, apart from the external point i \ (i \) the first point to the left of point win (If not pr [i] = 0), then the pr [i] of transfer can write:

\ (a [i] \) is odd, if \ (a [im-1] \) is odd, the \ (PR [I] = IM-. 1 \) , or \ (pr [i] = pr [ . 1-IM] \) .

\ (a [i] \) is an even number, if \ (a [im-1] \) is odd, the \ (PR [I] = I-. 1 \) , or \ (pr [i] = pr [ . 1-I] \) .

Such processing \ (pr \) after the \ (pr [i] \) as \ (i \) father point, \ (i \) ancestor node is represented as \ (i \) when the right endpoint the win points briefly proof: since \ (pr [i] \) in \ (I \) is the right end of the right may be regarded as an equivalent point, the \ (pr [pr [i] ] \) must also the point is to win the same token, the ancestors of all points.

So this time is the meaning of the questions: \ (L \) whether it is \ (r \) ancestors point. If so, just get wins, no, FLAC wins. The flip wins contributions add up to answer. Of course, if the \ (a [r] \) is even, then the relationship must win (l \ neq r \) \ it satisfies the conditions. About the structure tree, think about why the tree is so, think about why the \ (a [r] \) is even require special sentence, if understand this basic idea, no problem.

Tree relationship

As to whether it is seeking ancestor point, static tree structure, \ (DFN \) sequence recorded on the line.

#include <bits/stdc++.h>
using namespace std;

int n,m,Q,cnt,op;
int pr[1000005];
vector<int> q[1000005];
int dfn[1000005];
int siz[1000005];
int a[1000005];

int A,B,C,P;
inline int rnd(){return A=(A*B+C)%P;}

long long ans;
long long mod=(1ll<<32);
void dfs(int x){
    cnt++;dfn[x]=cnt;
    for(int i=0;i<q[x].size();i++){
        int nx=q[x][i];
        dfs(nx);
        siz[x]+=siz[nx];
    }
    siz[x]++;
}

int main(){
    scanf("%d%d%d%d",&n,&m,&Q,&op);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(a[i]%2==1){
            int nx=max(i-m-1,0);
            //cout<<nx<<endl;
            if(a[nx]%2)pr[i]=nx;
            else pr[i]=pr[nx];
        }
        else{
            if(a[i-1]%2)pr[i]=i-1;
            else pr[i]=pr[i-1];
        }
        //cout<<i<<"  "<<pr[i]<<endl;
        q[pr[i]].push_back(i);
    }

    dfs(0);

    if(op)scanf("%d%d%d%d",&A,&B,&C,&P);

    for(long long i=1;i<=Q;i++){
        int l,r;
        if(op){
            l=rnd()%n+1,r=rnd()%n+1;
        }
        else{scanf("%d%d",&l,&r);}
        if(l>r)swap(l,r);
        if(l==r){
            if(a[l]%2==0)ans=(ans+i*i)%mod;
            continue;
        }
        if(m==0){
            if(a[l]%2==0)ans=(ans+i*i)%mod;
            continue;
        }
        if(dfn[l]+siz[l]-1>=dfn[r]&&dfn[l]<=dfn[r]){

        }
        else ans=(ans+i*i)%mod;
    }
    printf("%lld\n",ans);
    return 0;
}

Guess you like

Origin www.cnblogs.com/redegg/p/11857307.html