版本比较
笛卡尔树
正文
增加 6 行删除 6 行
11 行未改动12131415161718192028 行未改动49505152535455565714 行未改动72737475767778798015 行未改动96979899100101102103104105106107108109110111112113147 行未改动全部展开26126226326426526626726826931 行未改动11 行未改动using namespace std;int n;int a[10000010];int t[10000010];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];//左儿子,右儿子,父亲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;//这是根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);}//先建小根笛卡尔树clear();for (int i=n;i>=1;i--){31 行未改动11 行未改动12131415161718192028 行未改动49505152535455565714 行未改动72737475767778798015 行未改动96979899100101102103104105106107108109110111112113147 行未改动全部展开26126226326426526626726826931 行未改动11 行未改动using namespace std;int n;int a[10000010];int t[10000010];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];//左儿子,右儿子,父亲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;//这是根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);}//先建小根笛卡尔树clear();for (int i=n;i>=1;i--){31 行未改动