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.
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
题目大意:
根据题目给的输入方式,计算出要更新的区间的左端点,右端点,要更新的值,如果要更新的值大于序列元素的值就进行更新操作,否则不变。
题解:
也就是说,每次的更新都要保存最大值,所以我们可以考虑反向RMQ,即小区间通过与大区间的比较确定值。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
using namespace std;
unsigned x,y,z;
int n,m;
unsigned rng61()
{
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;
}
const int maxn = 100000 + 10;
int a[maxn][25];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%u%u%u",&n,&m,&x,&y,&z);
for(int i=0;i<=n;i++)
{
for(int j=0;j<=16;j++)
{
a[i][j]=0;
}
}
for(int i=1;i<=m;i++)
{
int l,r,v,k=0;
l=rng61()%n+1;
r=rng61()%n+1;
v=rng61()%(1<<30);
if(l>r) swap(l,r);
while((1<<(k+1))<=r-l+1) k++;
a[l][k]=max(a[l][k],v);
a[r-(1<<k)+1][k]=max(a[r-(1<<k)+1][k],v);
}
for(int j=16;j>=1;j--)
{
for(int i=1;i+(1<<j)-1<=n;i++)
{
a[i][j-1]=max(a[i][j-1],a[i][j]);
a[i+(1<<(j-1))][j-1]=max(a[i][j],a[i+(1<<(j-1))][j-1]);
}
}
long long ans=0;
for(int i=1;i<=n;i++)
{
ans^=i*(long long)a[i][0];
}
printf("%lld\n",ans);
}
return 0;
}