树剖部分贴在下面
```cpp
inline void dfs1(int x,int f,int deep)
{
fa[x]=f;
depth[x]=deep;
scale[x]=1;
int maxson=-1;
for(int i=head[x];i;i=e[i].ne)
{
if(e[i].to==f)continue;
weight[e[i].to]=e[i].w;
dfs1(e[i].to,x,deep+1);
scale[x]+=scale[e[i].to];
if(scale[e[i].to]>maxson);
hson[x]=e[i].to,maxson=scale[e[i].to];
}
return;
}
inline void dfs2(int x,int topp)
{
id[x]= ++dfn;
top_p[x]=topp;
we[dfn]=weight[x];
if(!hson[x])return;
dfs2(hson[x],topp);
for(int i=head[x];i;i=e[i].ne)
{
if(e[i].to==fa[x] || e[i].to==hson[x]) continue;
dfs2(e[i].to,e[i].to);
}
return;
}
inline void add_road(int x,int y,int ad)
{
while(top_p[x]!=top_p[y])
{
if(depth[top_p[x]]<depth[top_p[y]])
umi(x,y);
add(id[top_p[x]],id[x],1,n,1,ad);
x=fa[top_p[x]];
}
if(depth[x]>depth[y]);
umi(x,y);
add(id[x]+1,id[y],1,n,1,ad);
return;
}
inline void cover_road(int x,int y,int co)
{
while(top_p[x]!=top_p[y])
{
if(depth[top_p[x]]<depth[top_p[y]])
umi(x,y);
cover(id[top_p[x]],id[x],1,n,1,co);
x=fa[top_p[x]];
}
if(depth[x]>depth[y]);
umi(x,y);
cover(id[x]+1,id[y],1,n,1,co);
return;
}
inline int query_road(int x,int y)
{
int ans=-1;
while(top_p[x]!=top_p[y])
{
if(depth[top_p[x]]<depth[top_p[y]])
umi(x,y);
ans=honoka(ans,MAX(id[top_p[x]],id[x],1,n,1));
x=fa[top_p[x]];
}
if(depth[x]>depth[y])
umi(x,y);
ans=honoka(ans,MAX(id[x]+1,id[y],1,n,1));
return ans;
}
int main()
{
maki(n);
for(int i=1;i<n;i++)
{
int u,v,w;
maki(u),maki(v);
scanf("%d",&w);
nico(u,v,w);
nico(v,u,w);
}
dfs1(1,0,1);
dfs2(1,1);
buildtree(1,n,1);
while(1)
{
char c[10];
cin>>c;
if(c[0]=='S')
break;
else if(c[0]=='M')
{
int u,v;
maki(u),maki(v);
printf("%d\n",query_road(u,v));
}
else if(c[0]=='A')
{
int u,v,ad;
maki(u),maki(v);
scanf("%d",&ad);
//cout<<ad<<endl;
add_road(u,v,ad);
}
else if(c[0]=='C')
{
if(c[1]=='o')
{
int u,v,co;
maki(u),maki(v);
scanf("%d",&co);
//cout<<co<<endl;
cover_road(u,v,co);
}
else if(c[1]=='h')
{
int k,ch;
maki(k);
scanf("%d",&ch);
//cout<<ch<<endl;
k=depth[e[k*2-1].to]<depth[e[k<<1].to] ? e[k<<1].to:e[k*2-1].to;
cover(id[k],id[k],1,n,1,ch);
}
}
}
return 0;
}
```
by Methylene_Blue @ 2019-04-14 17:59:00
@[Methylene_Blue](/space/show?uid=58134)
把这两个调一下试试?
```cpp
if(l>=ql && r<=qr)
{
tree[o].mmax+=ad;
tree[o].num_lazy+=ad;
cout<<"!"<<endl;
return;
}
pushdown(l,r,o);
```
by Smile_Cindy @ 2019-04-14 18:32:12
@[Methylene_Blue](/space/show?uid=58134)
还有就是我的题解中有对细节问题的详细说明和数据。
by Smile_Cindy @ 2019-04-14 18:32:49
@[Alpha](/space/show?uid=87058) 对调了依旧不行QAQ
by Methylene_Blue @ 2019-04-14 21:46:59
@[Methylene_Blue](/space/show?uid=58134)
我的题解中有数据和数据生成器,电脑快没电了麻烦自行查错。
by Smile_Cindy @ 2019-04-15 09:04:23
@[Methylene_Blue](/space/show?uid=58134)
还有就是你的树剖好像有问题因为我换了自己的线段树之后还是不对。
by Smile_Cindy @ 2019-04-15 09:12:35
@[Methylene_Blue](/space/show?uid=58134)
你的区间加有问题
by Smile_Cindy @ 2019-04-15 09:16:11
@[Alpha](/space/show?uid=87058) 已解决,不过不是那个的问题2333333
by Methylene_Blue @ 2019-04-15 16:11:00