Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1039 Accepted Submission(s): 404
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.
题意:更新区间里面比当前值小的数;
做法:典型的线段树区间,不过用线段树需要剪枝,毕竟线段树比较慢。
还有一个做法是用st,rmq,只需要把查询改成更新,更新改成查询就好了。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5+7;
int st[N][20];
int lg[N];
unsigned int x,y,z;
void init(){
lg[1] = 0;
int now = 2;
for(int i = 2;i < N;i ++){
lg[i] = lg[i-1];
if(i > now) lg[i]++,now*=2;
}
}
unsigned int get(){
x = x^(x<<11);
x = x^(x>>4);
x = x^(x<<5);
x = x^(x>>14);
unsigned int w = x^y^z;
x = y;
y = z;
z = w;
return z;
}
void update(int l,int r,int x){
int l2 = lg[r-l+1];
st[l][l2] = max(st[l][l2],x);
st[r-(1<<l2)+1][l2] = max(st[r-(1<<l2)+1][l2],x);
}
long long get(int n){
int l2 = lg[n];
for(int i = l2;i >= 1;i --){
for(int j = 1;j <= n;j ++){
if(j+(1<<i)> n+1) break;
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]);
}
}
long long ret = 0;
for(int i = 1;i <= n;i ++){
ret ^= 1LL*i*st[i][0];
}
return ret;
}
void set0(int n){
int l2 = lg[n];
for(int i = 0;i <= l2;i ++){
for(int j = 1;j <= n;j ++) st[j][i] = 0;
}
}
int main(){
init();
int T;
cin >> T;
while(T--){
//memset(st,0,sizeof(st));
int n,m;
scanf("%d %d",&n,&m);
set0(n);
scanf("%u %u %u",&x,&y,&z);
for(int i = 1;i <= m;i ++){
int l = get()%n+1,r = get()%n+1,v =get()%(1<<30);
if(l > r) swap(l,r);
update(l,r,v);
}
printf("%lld\n",get(n));
}
return 0;
}