蒟蒻只AC两个点,求助
#include<bits/stdc++.h>
using namespace std;
#define N 8000100
inline int read(){
int x = 0, s = 1;
char c = getchar();
while(!isdigit(c)){
if(c == '-') s = -1;
c = getchar();
}
while(isdigit(c)){
x = (x << 1) + (x << 3) + (c ^ '0');
c = getchar();
}
return x * s;
}
namespace get_data{
#define ui unsigned int
ui s;
inline void get_s(){
cin >> s;
return ;
}
inline ui get(ui x) {
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
return s = x;
}
}
struct node{
int u, v;
int next;
} t[N << 2];
int f[N];
int fa[N], son[N];
int rev[N], dfn[N], id = 0;
int sz[N], top[N], deth[N];
int ltans[N];
int bian = 0;
inline void add(int u, int v){
t[++bian] = (node){u, v, f[u]}, f[u] = bian;
t[++bian] = (node){v, u, f[v]}, f[v] = bian;
return ;
}
void dfs1(int now){
sz[now] = 1;
deth[now] = deth[fa[now]] + 1;
int maxn = -1;
for(int i = f[now]; i;i = t[i].next){
int v = t[i].v, u = t[i].u;
if(v != fa[u]){
dfs1(v);
sz[u] += sz[v];
if(sz[v] > maxn){
son[u] = v;
maxn = sz[v];
}
}
}
return ;
}
void dfs2(int now, int rt){
top[now] = rt, dfn[now] = ++id, rev[id] = now;
if(!son[now]) return ;
dfs2(son[now], rt);
for(int i = f[now]; i;i = t[i].next){
int v = t[i].v, u = t[i].u;
if(v != fa[u] && v != son[u]){
dfs2(v, v);
}
}
return ;
}
int jump(int x, int k){
int d = deth[x] - k;
while(deth[top[x]] > d) x = fa[top[x]];
d = deth[x] - d;
return rev[dfn[x] - d];
}
int main(){
int n = read(), q = read(); get_data::get_s();
int root;
for(int i = 1;i <= n; i++){
fa[i] = read();
add(fa[i], i);
if(fa[i] == 0) root = i;
}
deth[root] = 1;
dfs1(root);
dfs2(root, root);
int ans = 0;
for(int i = 1;i <= q; i++){
int x = ((get_data::get(get_data::s) ^ ltans[i-1] ) % n) + 1;
int k = (get_data::get(get_data::s) ^ ltans[i-1] ) % deth[x];
ltans[i] = jump(x, k);
ans ^= (i * ltans[i]);
}
printf("%d\n", ans);
return 0;
}