版本比较
冷门科技 —— DFS 序求解 LA
正文
增加 18 行删除 15 行
84 行未改动85868788899090919192939495969798991001011026 行未改动10911011111210611311410810911011111211511411611711811711811912012112012212312412512412612712812712812913013113213313413513 行未改动84 行未改动:::success[]```cpp line-numbers#include<bits/stdc++.h>using namespace std;/*快读略去*/int n,q,dep[500005],cnt,r[500005];vector<int>g[500005];vector<pair<int,int>>vec[500005];basic_string<int>g[500005];struct node{ int a,b; __inline bool operator<(int t)const{ return a<t; }};basic_string<node>vec[500005];unsigned s;inline unsigned get(unsigned x){ x^=x<<13; x^=x>>17;6 行未改动 dep[v]=dep[u]+1; dfs(v); r[u]=max(r[u],r[v]); } vec[dep[u]].push_back({r[u],u}); vec[dep[u]]+={r[u],u};}void read(auto&x){ char c(getchar()); while(c<'0')c=getchar(); while(c>='0')x=(x<<1)+(x<<3)+(c^48),c=getchar();}signed main(){ read(n),read(q),read(s); cin>>n>>q>>s; int rt=0; for(int i=1;i<=n;i++){ int f(0); read(f); int f; cin>>f; rt+=(!f)*i; g[f].push_back(i); g[f]+=i; } dep[rt]=1; dfs(rt); int lst=0; unsigned lst=0; long long sum=0; for(int i=1;i<=q;i++){ int u=(get(s)^lst)%n+1,k=(get(s)^lst)%dep[u]; lst=lower_bound(vec[dep[u]-k].begin(),vec[dep[u]-k].end(),make_pair(r[u],-1))->second; int u((get(s)^lst)%n+1),k((get(s)^lst)%dep[u]); k==0?lst=u: lst=lower_bound(vec[dep[u]-k].begin(),vec[dep[u]-k].end(),r[u])->b; sum^=1ll*i*lst; } cout<<sum; return 0;13 行未改动