1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
const int N=5e6+10,INF=1e9;
int n,m; int a[N],b[N]; ull k1,k2; int Shift(){ ull k3=k1,k4=k2; k1=k4; k3^=k3<<23; k2=k3^k4^(k3>>17)^(k4>>26); return (k2+k4)%10000000+1; } int A[N*3],B[N*3]; ll dp[3];
int main(){ while(~scanf("%d%d%llu%llu",&n,&m,&k1,&k2)) { rep(i,1,n) a[i]=Shift(),b[i]=Shift()+a[i]; sort(a+1,a+n+1,greater<int>()),sort(b+1,b+n+1,greater<int>());
A[0]=B[0]=1; rep(i,0,2) dp[i]=0; ll ans=0; int cur=0; rep(i,0,m) { if(i+1<=m && A[i]<=n) { int nxt=(cur+1)%3; if(dp[cur]+a[A[i]]>dp[nxt]) dp[nxt]=dp[cur]+a[A[i]],A[i+1]=A[i]+1,B[i+1]=B[i]; } if(i+2<=m && B[i]<=n) { int nxt=(cur+2)%3; if(dp[cur]+b[B[i]]>dp[nxt]) dp[nxt]=dp[cur]+b[B[i]],A[i+2]=A[i],B[i+2]=B[i]+1; } ans^=dp[cur]; cur=(cur+1)%3; } printf("%lld\n",ans); } }
|