P1501 [国家集训队]Tree II 题目描述 一棵\(n\)个点的树,每个点的初始权值为\(1\).对于这棵树有\(q\)个操作,每个操作为以下四种操作之一: + u v c:将\(u\)到\(v\)的路径上的点的权值都加上自然数\(c\): - u1 v1 u2 v2:将树中原有的边\((u_1,v_1)\)删除,加入一条新边\((u_2,v_2)\),保证操作完之后仍然是一棵树: * u v c:将\(u\)到\(v\)的路径上的点的权值都乘上自然数\(c\): / u v:询问\(u…
题目大意:给一棵$n(n\leqslant2\times10^5)$个叶子的二叉树,可以交换每个点的左右子树,要求前序遍历叶子的逆序对最少.输出最少的逆序对个数 题解:线段树合并,对于每个节点求出交换左右子树和不交换的答案. 卡点:没开$long\;long$ C++ Code: #include <cstdio> #define maxn 200010 #define N maxn * 20 inline long long min(long long a, long long b) {re…
题目传送门 Tree Rotation 题目描述 Byteasar the gardener is growing a rare tree called Rotatus Informatikus. It has some interesting features: The tree consists of straight branches, bifurcations and leaves. The trunk stemming from the ground is also a branch.…