版本比较
笛卡尔树
正文
增加 6 行删除 6 行
11 行未改动1213141516161718192028 行未改动4950515253535455565714 行未改动7273747576767778798015 行未改动96979899100100101102103104105106107108109109110111112113147 行未改动全部展开26126226326426526526626726826931 行未改动11 行未改动using namespace std;int n;int a[10000010];int t[10000010];int l[10000010],r[10000010],p[10000010];//l,r如题,p 是并查集 int l[10000010],r[10000010],p[10000010];//l,r如题,p 是并查集
inline int find(const int x){ if(p[x]==x) return x; p[x] = find(p[x]);28 行未改动 L ^= h; merge(pos-1,pos); } else L ^= pos;
if(a[pos+1]>a[pos]){ register long long h = pos; h *= (1+find(pos+1)); R ^= h;14 行未改动#define FAST ios::sync_with_stdio(false);cin.tie(0)using namespace std;int n;int a[10000010];int l[10000010],r[10000010];//左儿子,右儿子,父亲 int l[10000010],r[10000010];//左儿子,右儿子,父亲
inline int qread(){ int c,ret; while((c=getchar())> '9'||c< '0');15 行未改动 f = st.top(); st.pop(); } if(!st.empty()) r[st.top()] = i; else root = i;//这是根 else root = i;//这是根 l[i] = f; st.push(i); } long long L = 0,R = 0; for (int i=1;i<=n;i++){ long long h = i; h *= (1+l[i]); L ^= h;
h = i; h *= (1+r[i]); R ^= h; }147 行未改动全部展开 for (int i=1;i<=n-1;i++){ int x,y; cin >> x >> y; v[x].push_back(y); v[y].push_back(x); v[y].push_back(x); } //先建小根笛卡尔树 clear(); for (int i=n;i>=1;i--){31 行未改动