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): 1844    Accepted Submission(s): 795


 

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

Hint

In the first sample, a = [1031463378] after all the operations. In the second sample, a = [1036205629, 1064909195, 1044643689, 1062944339, 1062944339, 1062944339, 1062944339, 1057472915, 1057472915, 1030626924] after all the operations.

题意:让你按照题意生成3*m个数,然后a数组初始化全为0,按题意求每一个v[i],l[i],r[i],把区间[l[i],r[i]]小于v[i]的a[i]全部替换为v[i]。求 异或(i*a[i])(i=1,2,...,n)。

思路:比赛的时候只想到了线段树,赛后正解是倍增,其实就是ST表反着做,用大区间更新小区间。。。

代码:

#include <bits/stdc++.h>
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int maxn=1e5+10;
const int INF=0x3f3f3f3f;
const int mod=(1<<30);
unsigned  x,y,z;
unsigned  f[15000010];
unsigned  a[maxn][25];
unsigned  lg[maxn];
unsigned  get()
{
    x=x^(x<<11);
    x=x^(x>>4);
    x=x^(x<<5);
    x=x^(x>>14);
    unsigned w=x^(y^z);
    x=y;
    y=z;
    z=w;
    return z;
}
int main()
{
    int t;
    for(int i=2;i<maxn;i++)lg[i]=lg[(i>>1)]+1;
    scanf("%d",&t);
    while(t--)
    {
        memset(a,0,sizeof(a));
        int n,m;
        scanf("%d%d%d%d%d",&n,&m,&x,&y,&z);
        for(int i=1;i<=3*m;i++)
        {
            f[i]=get();
        }
        for(int i=1;i<=m;i++)
        {
            int l=min(f[3*i-2]%n+1,f[3*i-1]%n+1);
            int r=max(f[3*i-2]%n+1,f[3*i-1]%n+1);
            unsigned v=f[3*i]%mod;
            int d=lg[r-l+1];
            a[l][d]=max(a[l][d],v);
            a[r-(1<<d)+1][d]=max(a[r-(1<<d)+1][d],v);//RMQ的反查询
        }
        for(int i=lg[n];i>0;i--)
        {
            for(int j=1;j+(1<<i)-1<=n;j++)
            {
                a[j][i-1]=max(a[j][i-1],a[j][i]);
                a[j+(1<<i-1)][i-1]=max(a[j+(1<<i-1)][i-1],a[j][i]);//RMQ的反着更新
            }
        }
        ll sum=0;
        for(int i=1;i<=n;i++)
        {
            sum^=((ll)a[i][0]*(ll)i);
        }
        printf("%lld\n",sum);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值