题目链接
import java.util.*;
public class Main {
private static Scanner sc=new Scanner(System.in);
static long p,seed;
static int n,m,k;
public static void main(String[] args) throws Exception {
int t=1;
p=1L<<32;
//System.out.println(p);
// t=sc.nextInt();
while(t-->0){
solve();
}
sc.close();
}
static void solve(){
//System.out.println(p);
n=sc.nextInt();
m=sc.nextInt();
k=sc.nextInt();
seed=sc.nextInt();
long [][]a=new long[n+1][m+1];
ArrayList<ArrayList<Integer>>mp=new ArrayList<>();
mp.add(new ArrayList<>());
for(int i=1;i<=m;i++){
mp.add(new ArrayList<>());
for(int j=1;j<=n;j++){
mp.get(i).add(j);
a[j][i]=0;
}
}
while(k-->0){
long op=(rnd()%2)+1;
if(op==1){
int i=(int)(rnd() % m) + 1;
int x=(int)(rnd() % (n*m)) + 1;
if(mp.get(i).size()>0){
for(Integer tm:mp.get(i)){
a[tm][i]=x;
}
mp.get(i).clear();
}
// System.out.println(op+" "+i+" "+x);
}
else{
int x=(int)(rnd() % n) + 1;
int y=(int)(rnd() % m) + 1;
if(a[x][y]!=0){
a[x][y]=0;
mp.get(y).add(x);
}
// System.out.println(op+" "+x+" "+y);
}
}
long ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
ans^=(a[i][j]*((i-1)*m+j));
}
}
System.out.println(ans);
}
static long rnd(){
//System.out.println(seed);
long ret=seed;
seed=((seed^((seed<<13)%p))%p);
// System.out.println(seed);
seed=((seed^((seed>>>17)%p))%p);
//System.out.println(seed);
seed=((seed^((seed<<5)%p))%p);
//System.out.println(seed);
return ret;
}
}
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
unsigned seed;
unsigned rnd(){
unsigned ret=seed;
seed^=seed<<13;
seed^=seed>>17;
seed^=seed<<5;
return ret;
}
int op[5010000],x[5001000],T[5010000],a[210][20100];
bool vis[20010];
#define pb push_back
vector<int>g[210];
int main(){
scanf("%d%d%d%u",&n,&m,&k,&seed);
for(int i=1;i<=m;i++)for(int j=1;j<=n;j++)g[i].emplace_back(j);
for(int t=1,op;t<=k;t++){
op=(rnd() % 2) + 1;
if(op==1){
int i=(rnd()% m) + 1,x=(rnd() % (n*m)) + 1;
for(int e:g[i])a[i][e]=x;
g[i].clear();
}
else{
int x=rnd()%n+1,y=rnd()%m+1;
if(a[y][x])a[y][x]=0,g[y].push_back(x);
}
}
long long ans=0;
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)
ans^=1ll*a[j][i]*((i-1)*m+j);
printf("%lld",ans);
return 0;
}