hdu 6356 Glad You Came(倍增)

Glad You Came

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 777    Accepted Submission(s): 269


 

Problem Description

Steve has an integer array a of length n (1-based). He assigned all the elements as zero at the beginning. After that, he made m operations, each of which is to update an interval of a with some value. You need to figure out ⨁ni=1(i⋅ai) after all his operations are finished, where ⨁ means the bitwise exclusive-OR operator.
In order to avoid huge input data, these operations are encrypted through some particular approach.
There are three unsigned 32-bit integers X,Y and Z which have initial values given by the input. A random number generator function is described as following, where ∧ means the bitwise exclusive-OR operator, << means the bitwise left shift operator and >> means the bitwise right shift operator. Note that function would change the values of X,Y and Z after calling.


Let the i-th result value of calling the above function as fi (i=1,2,⋯,3m). The i-th operation of Steve is to update aj as vi if aj<vi (j=li,li+1,⋯,ri), where

⎧⎩⎨⎪⎪lirivi=min((f3i−2modn)+1,(f3i−1modn)+1)=max((f3i−2modn)+1,(f3i−1modn)+1)=f3imod230(i=1,2,⋯,m).

Input

The first line contains one integer T, indicating the number of test cases.
Each of the following T lines describes a test case and contains five space-separated integers n,m,X,Y and Z.
1≤T≤100, 1≤n≤105, 1≤m≤5⋅106, 0≤X,Y,Z<230.
It is guaranteed that the sum of n in all the test cases does not exceed 106 and the sum of m in all the test cases does not exceed 5⋅107.

Output

For each test case, output the answer in one line.

Sample Input

 

4 1 10 100 1000 10000 10 100 1000 10000 100000 100 1000 10000 100000 1000000 1000 10000 100000 1000000 10000000

Sample Output

 

1031463378 1446334207 351511856 47320301347

思路:
倍增,用大区间更新小区间。

代码:

#include<bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define ll long long
const int maxn=1e5+10;
const uint mod=(1<<30);
int f[maxn][22],lg[maxn];
uint t[maxn*55];
uint x,y,z;
uint get_ans()
{
    ll w;
    x=x^(x<<11);
    x=x^(x>>4);
    x=x^(x<<5);
    x=x^(x>>14);
    w=x^(y^z);
    x=y;
    y=z;
    z=w;
    return z;
}
void update(int &x,int y)
{
    x=max(x,y);
}
int main()
{
    for(int i=2;i<maxn;i++)
        lg[i]=lg[i/2]+1;
    int T;scanf("%d",&T);
    while(T--)
    {
        ll n,m;
        cin>>n>>m>>x>>y>>z;
        for(int i=1;i<=m;i++)
        {
            int L=get_ans()%n+1;
            int R=get_ans()%n+1;
            int v=get_ans()&((1<<30)-1);
            if(L>R) swap(L,R);
            int d=lg[R-L+1];
            update(f[L][d],v);
            update(f[R-(1<<d)+1][d],v);
        }
        for(int i=lg[n];i>0;i--)
        {
            for(int j=1;j+(1<<i)-1<=n;j++)
            {
                update(f[j][i-1],f[j][i]);
                update(f[j+(1<<i-1)][i-1],f[j][i]);
                f[j][i]=0;
            }
        }
        ll ans=0;
        for(ll i=1;i<=n;i++)
        {
            ans=ans^(i*f[i][0]);
            f[i][0]=0;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/albertluf/article/details/81461952
今日推荐