Glad You Came
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2187 Accepted Submission(s): 959
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
Recommend
chendu
Statistic | Submit | Discuss | Note
题意:有m次操作,每次在l到r这个区间中,让a[i]=max(a[i],v),最后得出每一位数字*i的异或和。
题解:每次告诉一个区间的最大值,最后让你求出每一个数字,其实可以考虑用一下ST表,其实是ST表的逆用,对于每一次区间的修改都变成ST表的查询操作,将这个区间分成两段,每一段都维护一下最大值v,最后再由大区间慢慢缩成小的区间,将每个区间分成两段,前半段维护和整个区间的最大值,后半段同样维护和整个区间的最大值,最后进行计算即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+7;
typedef pair<ll,ll> PII;
int lg[maxn];
unsigned int x,y,z;
unsigned int 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;
}
int dp[maxn][50];
void update(int &x,int y)
{
x=max(x,y);
}
int main()
{
for(int i=2;i<maxn;i++)
lg[i]=lg[i>>1]+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(dp[l][d],v);
update(dp[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(dp[j][i-1],dp[j][i]);
update(dp[j+(1<<i-1)][i-1],dp[j][i]);
dp[j][i]=0;
}
ll ans=0;
for(ll i=1;i<=n;i++)
{
ans=ans^(i*dp[i][0]);
dp[i][0]=0;
}
printf("%lld\n",ans);
}
return 0;
}