HDU 6356 Glad You Came 反向 更新ST表

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lifelikes/article/details/81462116

Glad You Came
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 795 Accepted Submission(s): 279

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.

题意 :
给出一个数据生成器,由数据生成器给出m次操作。
每次操作由一个三元组组成(l,r,v)
将l-r 之间的小于v的元素全部更新为v。
问最后⨁ni=1(i⋅ai)
解题思路:
被教育了啊,完全想不到啊。
因为只有一次查询 ,所以可以静态处理。
静态处理区间最值常用的即使rmq 也就是st表。
这里有m次区间操作,我们可以插入所有点后,反向更新st表。 tql tql

#include<iostream>
#include <cstdio>
using namespace std;
const int MAX = 1e5+10;
int st[MAX][20];
int log[MAX];
unsigned int x,y,z;
unsigned int rng61(){
    unsigned int 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 init(){
    int cnt = 1;
    for(int i=2;i<MAX;i++){
        log[i]=log[i>>1]+1;
    }
}
int main(){
    int l,r,v;
    int T;
    init();
    scanf("%d",&T);
    while(T--){
        int l,r,v;
        int n,m;
        int top=0;
        cin>>n>>m>>x>>y>>z;
        while((1<<top) <n){
            top++;
        }
        while(m--){
            l=rng61()%n+1;
            r=rng61()%n+1;
            v=rng61()%(1<<30);
            if(l>r) swap(l,r);
            int dis=log[r-l+1];
            st[l][dis]=max(st[l][dis],v);
            st[r-(1<<dis)+1][dis]=max(st[r-(1<<dis)+1][dis],v);
        }
        for(int i=top-1;i>0;i--){
            for(int j=1;j+(1<<i)-1<=n;j++){
                st[j][i-1]=max(st[j][i-1],st[j][i]);
                st[j+(1<<(i-1))][i-1]=max(st[j+(1<<(i-1))][i-1],st[j][i]);
                st[j][i]=0;
            }
        }
        long long ans=0;
        for(long long i=1;i<=n;i++){
            ans ^= i*st[i][0];
            st[i][0]=0;
        }
        cout<<ans<<endl;
    }
}

猜你喜欢

转载自blog.csdn.net/lifelikes/article/details/81462116
今日推荐