Glad You Came
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 569 Accepted Submission(s): 180
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.
Source
2018 Multi-University Training Contest 5
题意:数组有n个数初始为0,m个询问,每个询问给出L R V(按照给定函数生成),将数组的下标L到R的数与V取较大值,最后输出给定的公式结果。
思路:学习了新东西,区间最值修改,容易想到线段树,但是我写的超时了。。。考虑将L R拆成两个可重叠的区间且长度均为2的幂次,然后从长到短、从1到n对半维护最值,复杂度O(nlogn),就是ST表的反转做法。
# include <bits/stdc++.h>
# define lson l,mid,id<<1
# define rson mid+1,r,id<<1|1
using namespace std;
typedef long long LL;
typedef unsigned int ui;
const int maxn = (5e6+30)*3;
ui x, y, z, a[100003][18], b[maxn];
int lg[100003]={0};
ui fun()
{
x = x^(x<<11);
x = x^(x>>4);
x = x^(x<<5);
x = x^(x>>14);
ui w = x^(y^z);
x = y;
y = z;
z = w;
return z;
}
int main()
{
int T, n, m;
for(int i=2; i<=100000; ++i) lg[i] = lg[i>>1]+1;
for(scanf("%d",&T); T; --T)
{
scanf("%d%d%u%u%u",&n,&m,&x,&y,&z);
int mx = max(n, 3*m), imax=0;
memset(a, 0, sizeof(a));
for(int i=1; i<=mx; ++i)
b[i] = fun();
for(int i=1; i<=m; ++i)
{
int l = min(b[3*i-2]%n+1, b[3*i-1]%n+1);
int r = max(b[3*i-2]%n+1, b[3*i-1]%n+1);
ui vi = b[3*i]%(1<<30);
int d = lg[r-l+1];
r = r+1-(1<<d);
a[l][d] = max(a[l][d], vi);
a[r][d] = max(a[r][d], vi);
imax = max(imax, d);
}
for(int i=imax; i>=1; --i)
{
for(int j=1, d=1<<i; j<=n; ++j)
{
if(j+d-1>n) break;
a[j][i-1] = max(a[j][i-1], a[j][i]);
a[j+(d>>1)][i-1] = max(a[j+(d>>1)][i-1], a[j][i]);
}
}
LL ans = 0;
for(int i=1; i<=n; ++i)
ans ^= 1LL*i*a[i][0];
printf("%lld\n",ans);
}
return 0;
}