#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const int maxn = (5e6+30)*3;
ui x, y, z, a[100003][18], b[maxn];
int lg[100003] = {0};
ui fun()
{
x = x^(x<<11);
x = x^(x>>4);
x = x^(x<<5);
x = x^(x>>14);
ui w = x^(y^z);
x = y;
y = z;
z = w;
return z;
}
int main()
{
int T, n, m;
for(int i = 2; i <= 100000; i++) lg[i] = lg[i>>1]+1;
for(scanf("%d", &T); T; --T)
{
scanf("%d%d%u%u%u", &n, &m, &x, &y, &z);
int mx = max(n, 3*m), imax = 0;
memset(a, 0, sizeof(a));
for(int i = 1; i <= mx; i++)
b[i] = fun();
for(int i = 1; i <= m; i++)
{
int l = min(b[3*i-2]%n+1, b[3*i-1]%n+1);
int r = max(b[3*i-2]%n+1, b[3*i-1]%n+1);
ui vi = b[3*i]%(1<<30);
int d = lg[r-l+1];
r = r+1-(1<<d);
a[l][d] = max(a[l][d], vi);
a[r][d] = max(a[r][d], vi);
imax = max(imax, d);
}
for(int i = imax; i >= 1; i--)
{
for(int j = 1, d = 1<<i; j <= n; j++)
{
if(j+d-1>n) break;
a[j][i-1] = max(a[j][i-1], a[j][i]);
a[j+(d>>1)][i-1] = max(a[j+(d>>1)][i-1], a[j][i]);
}
}
ll ans = 0;
for(int i = 1; i <= n; i++)
{
ans ^= 1ll*i*a[i][0];
}
printf("%I64d\n", ans);
}
return 0;
}
HDU6356 (ST)
猜你喜欢
转载自blog.csdn.net/QiHang_QiHang/article/details/81484860
今日推荐
周排行