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.
思路:x,y,z,w开unsigned int,
然后就是线段树暴力修改,维护一个区间最小值减支就行。
代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <string>
#include <math.h>
#include <stack>
using namespace std;
typedef unsigned int ll;
#define Lson l,m,rt<<1
#define Rson m+1,r,rt<<1|1
const int maxn = 1e5+10;
const int mod=1<<30;
#define inf 0x3f3f3f3f
ll n,m;
ll a[maxn];
ll x,y,z;
ll Funtion()
{
x=(x^(x<<11));
x=(x^(x>>4));
x=(x^(x<<5));
//cout<<"3 ....."<<x<<endl;
x=(x^(x>>14));
//cout<<"4 ...."<<x<<endl;
ll w=(x^(y^z));
// w%=n;
//cout<<"1 ..."<<w<<endl;
x=y;
y=z;
z=w;
return z;
}
ll b[maxn];
struct Tree
{
int cnt;
ll Maxa,Minb;
int add;
}tree[maxn<<2];
void push_up(int rt)
{
tree[rt].Minb=min(tree[rt<<1].Minb,tree[rt<<1|1].Minb);
}
void Build(int l,int r,int rt)
{
tree[rt].add=0;
if(l==r)
{
tree[rt].Minb=0;
return;
}
int m=l+r>>1;
Build(Lson);
Build(Rson);
push_up(rt);
}
void updata(int L,int R,int l,int r,int rt,ll v)
{
if(tree[rt].Minb>=v) return;//如果最小值都比v大,那么没有必要继续更新
if(L<=l&&R>=r)
{
if(tree[rt].Minb>=v)
{
return;
}
if(l==r)
{
if(tree[rt].Minb<v)
{
tree[rt].Minb=v;
}
return;
}
}
int m=l+r>>1;
if(L<=m) updata(L,R,Lson,v);
if(R>m) updata(L,R,Rson,v);
push_up(rt);
}
ll query(int L,int R,int l,int r,int rt)
{
if(L<=l&&R>=r)
{
return tree[rt].Minb;
}
int m=l+r>>1;
int ans=0;
if(L<=m) ans+=query(L,R,Lson);
if(R>m) ans+=query(L,R,Rson);
return ans;
}
#define ONLINE_JUDGE
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int T;
scanf("%d",&T);
while(T--)
{
scanf("%u%u%u%u%u",&n,&m,&x,&y,&z);
Build(1,n,1);
ll f1,f2,f3;
ll l,r,v;
for(int i=1;i<=3*m;i+=3)
{
f1=Funtion();
f2=Funtion();
f3=Funtion();
l=min(f1%n,f2%n)+1;
r=max(f1%n,f2%n)+1;
v=f3%mod;
updata(l,r,1,n,1,v);
}
long long ans=0;
for(ll i=1;i<=n;i++)
{
ll tmp=query(i,i,1,n,1);
ans^=(long long)tmp*i;
}
printf("%lld\n",ans);
}
return 0;
}