传送门
【题目分析】
qwq数据结构调起来真是有毒。
换根后只会对子树的查询和修改造成影响,很明显,如果修改位置x与root的lca非x,那么不会有影响,如果是x,那么分根是x和不是x两种情况,第一种输出tr[1].sum即可,第二种直接全体操作然后对x到rt第一个点子树进行操作即可。
【代码~】
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN=1e5+10;
const int MAXM=2e5+10;
int n,rt=1,q,cnt;
int a[MAXN];
int head[MAXN],depth[MAXN],siz[MAXN],fa[MAXN],son[MAXN],top[MAXN];
int nxt[MAXM],to[MAXM];
int dfn[MAXN],ys[MAXN],tot;
struct Tree{
int l,r;
LL add;
LL sum;
}tr[MAXN<<2];
int Read(){
int i=0,f=1;
char c;
for(c=getchar();(c>'9'||c<'0')&&c!='-';c=getchar());
if(c=='-')
f=-1,c=getchar();
for(;c