倍增写法WA50,悬三关
查看原帖
倍增写法WA50,悬三关
768530
Expert_Dream楼主2023/12/31 11:50
/*
Author: gsczl71
Copyright (c) 2023 gsczl71 All rights reserved.
problem:
*/

//#pragma omp parallel for num_threads(64)
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
//#pragma GCC optimize(2,3,"Ofast","inline","-fgcse","-fgcse-lm","-fipa-sra","-ftree-pre","-ftree-vrp","-fpeephole2","-ffast-math","-fsched-spec","unroll-loops","-falign-jumps","-falign-loops","-falign-labels","-fdevirtualize","-fcaller-saves","-fcrossjumping","-fthread-jumps","-funroll-loops","-freorder-blocks","-fschedule-insns","inline-functions","-ftree-tail-merge","-fschedule-insns2","-fstrict-aliasing","-falign-functions","-fcse-follow-jumps","-fsched-interblock","-fpartial-inlining","no-stack-protector","-freorder-functions","-findirect-inlining","-fhoist-adjacent-loads","-frerun-cse-after-loop","inline-small-functions","-finline-small-functions","-ftree-switch-conversion","-foptimize-sibling-calls","-fexpensive-optimizations","inline-functions-called-once","-fdelete-null-pointer-checks")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
//#pragma comment(linker,"/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//--------------------------------------------------------火车头

#include<bits/stdc++.h>
#include<vector> //有历史意义,我不想成为下一个hzlqwq
//#include<windows.h>

//--------------------------------------------------------头文件

#define ll long long
//#define int unsigned long long
#define i128 __int128
#define ull unsigned long long
#define pii pair<int,int>
#define fir first
#define se second
#define endl '\n'
#define debug puts("AK IOI RP INF")
#define debug1 puts("AK IOI -- part 1")
#define debug2 puts("AK IOI -- part 2")
#define debug3 puts("AK IOI -- part 3")
#define debug4 puts("AK IOI -- part 4")
#define re register
#define Yes puts("Yes")
#define No puts("No")
#define YES puts("YES")
#define NO puts("NO")
#define yes puts("yes")
#define no puts("no")
#define error puts("error")
#define IMPOSSIBLE puts("IMPOSSIBLE")
#define Impossible puts("Impossible")
#define fy puts("-1")
#define pll pair<long long, long long>
#define AC exit(0)
#define pb push_back

//-------------------------------------------------------define好习惯

using namespace std;
namespace gsczl71_function {
	inline int Min(int a, int b) {
		return a < b ? a : b;   //取min
	}
	inline int Max(int a, int b) {
		return a > b ? a : b;   //取max
	}
	inline void Swap(int& a, int& b) {
		a ^= b, b ^= a, a ^= b;   //交换
	}
	inline void tomin(int& a, int b) {
		if (a > b)a = b;   //a=min(a,b)
	}
	inline void tomax(int& a, int b) {
		if (a < b)a = b;   //a=max(a,b)
	}
	inline int Abs(int x) {
		return (x ^ (x >> 31)) - (x >> 31);   //绝对值
	}
	inline ll gcd(ll a, ll b) {
		/*最大公因数*/int i = __builtin_ctz(a), j = __builtin_ctz(b), x = i > j ? j : i, y;
		b >>= j;
		while (a) {
			a >>= i;
			y = b - a;
			i = __builtin_ctz(y);
			b = a < b ? a : b;
			a = y < 0 ? -y : y;
		}
		return b << x;
	}
	inline ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;   //最小公倍数
	}
	inline ll jc(ll x, ll p) {
		ll res = 1;    //x的阶乘模p
		if (p)for (ll i(1); i <= x; ++i)res = (res * i) % p;
		else for (ll i(1); i <= x; ++i)res = (res * i);
		return res;
	}
	inline ll Mod(ll x, ll y) {
		return x - y * (x / y);   //取模
	}
	inline ll ksm(ll a, ll b) {
		ll res = 1;    //快速幂
		while (b) {
			if (b & 1) res *= a;
			a *= a, b >>= 1;
		}
		return res;
	}
	inline ll ksm(ll a, ll b, ll p) {
		ll res = 1;    //快速幂模p
		while (b) {
			if (b & 1) res = (res * a) % p;
			a = (a * a) % p, b >>= 1;
		}
		return res;
	}
}
namespace gsczl71_fastIO {
	template <typename T = int>
	inline T read() {
		T s = 0, w = 1;
		char c = getchar();
		while (!isdigit(c)) {
			if (c == '-')w = -1;
			c = getchar();
		}
		while (isdigit(c))s = (s << 1) + (s << 3) + (c ^ 48), c = getchar();
		return s * w;
	} template <typename T>
	inline void read(T &s) {
		s = 0;
		int w = 1;
		char c = getchar();
		while (!isdigit(c)) {
			if (c == '-')w = -1;
			c = getchar();
		}
		while (isdigit(c))s = (s << 1) + (s << 3) + (c ^ 48), c = getchar();
		s *= w;
	} template <typename T, typename... Args> inline void read(T &x, Args &...args) {
		read(x), read(args...);
	}
	template <typename T>
	inline void write(T x, char ch) {
		if (x < 0)x = -x, putchar('-');
		static char stk[200];
		int top = 0;
		do {
			stk[top++] = x % 10 + '0', x /= 10;
		} while (x);
		while (top)putchar(stk[--top]);
		putchar(ch);
		return;
	}
}
//using namespace gsczl71_fastIO;
//using namespace gsczl71_function;
//-------------------------------------------------------主程序-----------------------------------------------------
//#define int long long
const int mod = 1e9 + 7;
//const int mod = 998244353;
const int inf = 0x3f3f3f3f, N = 5e5 + 5, M = 2e5 + 5;
const ll linf = 0x3f3f3f3f3f3f3f3f;
int fa[N][35];
ll res = 0;
#define ui unsigned int
ui s;

inline ui get(ui x) {
	x ^= x << 13;
	x ^= x >> 17;
	x ^= x << 5;
	return s = x;
}
ui ans[N];
int gen, dep[N];
vector<int> mp[N];
void dfs(int x, int fa) {
	for (auto it : mp[x]) {
		if (it == fa)continue;
		dep[it] = dep[x] + 1;
		dfs(it, x);
	}
	return ;
}
void solve() {
	int n, q;
	cin >> n >> q >> s;
	for (int i = 1; i <= n; i++) {
		cin >> fa[i][0];
		if (fa[i][0] == 0) gen = i;
		else mp[fa[i][0]].push_back(i);
	}
	dep[gen] = 1;
	dfs(gen, 0);

	for (int i = 1; i <= 31; i++) {
		for (int j = 1; j <= n; j++) {
			fa[j][i] = fa[fa[j][i - 1]][i - 1];
		}
	}
	for (int i = 1; i <= q; i++) {
		int x, k;
		x = ((get(s)^ans[i - 1]) % n) + 1;
		k = (get(s) ^ans[i - 1]) % dep[x];
//		cout<<get(s)<<endl;
//		cout<<(get(s) ^ans[i-1])<<" "<<dep[x];
		for (int j = 0; j <= 31; j++) {
			if ((1 << j) & k) x = fa[x][j];
		}
		ans[i] = x;
		res ^= 1ll * i * ans[i];

//		cout<<x<<" "<<k << " "<<dep[x]<<endl;
//		cout<<ans[i]<<endl;
//		cout<<i<<endl;
	}
	cout << res;

}

signed main() {
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
//	unsigned long long RP = -1;
//	freopen("P5903_6.in","r",stdin);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	int T = 1;
//	cin >> T;
	while (T--) solve();
	return 0;//华丽收尾
}
/*
*/


2023/12/31 11:50
加载中...