传送门

唉蒟蒻又退化了,这道sb题居然做了20min,最后发现是updcovupdcovupdcov写成了updaddupdaddupdadd我还能说什么233233233

就是让你转边权为点权之后,支持树上路径覆盖,单点覆盖,路径加,求路径最大。

直接乱码一发居然AAA了?

贴代码了(稍微有点长):

#include<bits/stdc++.h>
#define lc (p<<1)
#define rc (p<<1|1)
#define mid (T[p].l+T[p].r>>1)
using namespace std;
inline int read(){
	int ans=0;
	char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return ans;
}
const int N=1e5+5;
int n,m,first[N],top[N],dep[N],fa[N],siz[N],hson[N],pred[N],num[N],a[N],cnt=0,tot=0;
struct edge{int v,next,w;}e[N<<1];
inline void add(int u,int v,int w){e[++cnt].v=v,e[cnt].w=w,e[cnt].next=first[u],first[u]=cnt;}
void dfs1(int p){
	siz[p]=1;
	for(int i=first[p];i;i=e[i].next){
		int v=e[i].v;
		if(v==fa[p])continue;
		fa[v]=p,dep[v]=dep[p]+1,a[v]=e[i].w,dfs1(v),siz[p]+=siz[v];
		if(siz[v]>siz[hson[p]])hson[p]=v;
	}
}
void dfs2(int p,int tp){
	top[p]=tp,pred[num[p]=++tot]=p;
	if(!hson[p])return;
	dfs2(hson[p],tp);
	for(int i=first[p];i;i=e[i].next){
		int v=e[i].v;
		if(v!=fa[p]&&v!=hson[p])dfs2(v,v);
	}
}
struct Node{int l,r,mx,cov,add;}T[N<<2];
inline void pushup(int p){T[p].mx=max(T[lc].mx,T[rc].mx);}
inline void pushadd(int p,int v){T[p].mx+=v,T[p].add+=v;}
inline void pushcov(int p,int v){T[p].mx=v,T[p].cov=v,T[p].add=0;}
inline void pushdown(int p){
	if(~T[p].cov)pushcov(lc,T[p].cov),pushcov(rc,T[p].cov),T[p].cov=-1;
	if(T[p].add)pushadd(lc,T[p].add),pushadd(rc,T[p].add),T[p].add=0;
}
inline void build(int p,int l,int r){
	T[p].l=l,T[p].r=r,T[p].cov=-1;
	if(l==r){T[p].mx=a[pred[l]];return;}
	build(lc,l,mid),build(rc,mid+1,r),pushup(p);
}
inline void updadd(int p,int ql,int qr,int v){
	if(ql>T[p].r||qr<T[p].l)return;
	if(ql<=T[p].l&&T[p].r<=qr)return pushadd(p,v);
	pushdown(p);
	if(qr<=mid)updadd(lc,ql,qr,v);
	else if(ql>mid)updadd(rc,ql,qr,v);
	else updadd(lc,ql,mid,v),updadd(rc,mid+1,qr,v);
	pushup(p);
}
inline void updcov(int p,int ql,int qr,int v){
	if(ql>T[p].r||qr<T[p].l)return;
	if(ql<=T[p].l&&T[p].r<=qr)return pushcov(p,v);
	pushdown(p);
	if(qr<=mid)updcov(lc,ql,qr,v);
	else if(ql>mid)updcov(rc,ql,qr,v);
	else updcov(lc,ql,mid,v),updcov(rc,mid+1,qr,v);
	pushup(p);
}
inline int query(int p,int ql,int qr){
	if(ql>T[p].r||qr<T[p].l)return 0;
	if(ql<=T[p].l&&T[p].r<=qr)return T[p].mx;
	pushdown(p);
	if(qr<=mid)return query(lc,ql,qr);
	if(ql>mid)return query(rc,ql,qr);
	return max(query(lc,ql,mid),query(rc,mid+1,qr));
}
inline void changeadd(int x,int y,int v){
	while(top[x]^top[y]){
		if(dep[top[x]]<dep[top[y]])swap(x,y);
		updadd(1,num[top[x]],num[x],v),x=fa[top[x]];
	}
	if(dep[x]<dep[y])swap(x,y);
	updadd(1,num[y]+1,num[x],v);
}
inline void changecov(int x,int y,int v){
	while(top[x]^top[y]){
		if(dep[top[x]]<dep[top[y]])swap(x,y);
		updcov(1,num[top[x]],num[x],v),x=fa[top[x]];
	}
	if(dep[x]<dep[y])swap(x,y);
	updcov(1,num[y]+1,num[x],v);
}
inline int ask(int x,int y){
	int ret=0;
	while(top[x]^top[y]){
		if(dep[top[x]]<dep[top[y]])swap(x,y);
		ret=max(ret,query(1,num[top[x]],num[x])),x=fa[top[x]];
	}
	if(dep[x]<dep[y])swap(x,y);
	return max(ret,query(1,num[y]+1,num[x]));
}
int main(){
	n=read();
	for(int u,v,w,i=1;i<n;++i)u=read(),v=read(),w=read(),add(u,v,w),add(v,u,w);
	dfs1(1),dfs2(1,1),build(1,1,n);
	char s[10];
	while(1){
		scanf("%s",s);
		if(s[0]=='S')break;
		int x=read(),y=read();
		if(s[0]=='M')printf("%d\n",ask(x,y));
		if(s[0]=='C'&&s[1]=='o')changecov(x,y,read());
		if(s[0]=='A')changeadd(x,y,read());
		if(s[0]=='C'&&s[1]=='h'){
			int u=e[x*2].v,v=e[x*2-1].v;
			if(dep[u]>dep[v])swap(u,v);
			updcov(1,num[v],num[v],y);
		}
	}
	return 0;
}

2018.10.27 bzoj1984: 月下“毛景树”(树链剖分)的更多相关文章

  1. BZOJ1984: 月下“毛景树”

    1984: 月下“毛景树” Time Limit: 20 Sec  Memory Limit: 64 MBSubmit: 713  Solved: 245[Submit][Status] Descri ...

  2. [bzoj1984]月下“毛景树”

    Description 毛毛虫经过及时的变形,最终逃过的一劫,离开了菜妈的菜园.毛毛虫经过千山万水,历尽千辛万苦,最后来到了小小的绍兴一中的校园里.爬啊爬~爬啊爬~~毛毛虫爬到了一颗小小的" ...

  3. [BZOJ1984]月下“毛景树”解题报告|树链剖分

    Description 毛毛虫经过及时的变形,最终逃过的一劫,离开了菜妈的菜园. 毛毛虫经过千山万水,历尽千辛万苦,最后来到了小小的绍兴一中的校园里.爬啊爬~爬啊爬~~毛毛虫爬到了一颗小小的“毛景树” ...

  4. 【树链剖分】【分块】【最近公共祖先】【块状树】bzoj1984 月下“毛景树”

    裸题,但是因为权在边上,所以要先把边权放到这条边的子节点上,然后进行链更新/查询的时候不能更新/查询其lca. #include<cstdio> #include<cmath> ...

  5. 【BZOJ1984】月下“毛景树” 树链剖分+线段树

    [BZOJ1984]月下"毛景树" Description 毛毛虫经过及时的变形,最终逃过的一劫,离开了菜妈的菜园. 毛毛虫经过千山万水,历尽千辛万苦,最后来到了小小的绍兴一中的校 ...

  6. 【BZOJ-1984】月下“毛景树” 树链剖分

    1984: 月下“毛景树” Time Limit: 20 Sec  Memory Limit: 64 MBSubmit: 1314  Solved: 416[Submit][Status][Discu ...

  7. 树剖+线段树||树链剖分||BZOJ1984||Luogu4315||月下“毛景树”

    题面:月下“毛景树” 题解:是道很裸的树剖,但处理的细节有点多(其实是自己线段树没学好).用一个Dfs把边权下移到点权,用E数组记录哪些边被用到了:前三个更新的操作都可以合并起来,可以发现a到b节点间 ...

  8. BZOJ 1984: 月下“毛景树” [树链剖分 边权]

    1984: 月下“毛景树” Time Limit: 20 Sec  Memory Limit: 64 MBSubmit: 1728  Solved: 531[Submit][Status][Discu ...

  9. Bzoj 1984: 月下“毛景树” 树链剖分

    1984: 月下“毛景树” Time Limit: 20 Sec  Memory Limit: 64 MBSubmit: 1282  Solved: 410[Submit][Status][Discu ...

随机推荐

  1. HDU-1074.DoingHomework(撞鸭dp二进制压缩版)

    之前做过一道二进制压缩的题目,感觉也不是很难吧,但是由于见少识窄,这道题一看就知道是撞鸭dp,却总是无从下手....最后看了一眼博客,才顿悟,本次做这道题的作用知识让自己更多的认识二进制压缩,并无其它 ...

  2. JSON Extractor

    JMeter处理responses 的json 对于请求1返回的结果,处理以后作为请求2的参数,JMeter提供了JSON 提取器 比如 responses 返回: {"statusCode ...

  3. Angular之特性模块 ( Feature Module )

    项目结构 一 创建特性模块,及其包含的组件.服务. ng g module art ng g component art/music ng g component art/dance ng g ser ...

  4. Angular之模版引用变量

    A template reference variable is often a reference to a DOM element within a template. It can also b ...

  5. Delphi: 圆形进度(环形进度)

    起源: 重回DC5项目,资源下载美工提供圆形进度条,复习Delphi,为实现其颇觉有趣,遂研究其. 最终效果图如下: 实现: 制作TCircleProgress控件,实现方法参照系统之TGauge控件 ...

  6. cloud配置中心遇到的坑

    https://blog.csdn.net/z960339491/article/details/80593982分布式配置中心为什么要有用分布式配置中心这玩意儿?现在这微服务大军已经覆盖了各种大小型 ...

  7. 如何开发简单的javaweb项目,jsp+javabean+servlet

    一.相关的软件下载和环境配置 1.下载并配置JDK. 2.下载eclipse. 3.下载并配置apache-tomcat(服务器). 4.下载MySQL(数据库). 5.下载Navicat for M ...

  8. C语言常用标准库函数

    数学函数: 在math.h中 abs(x) :求整型数x的绝对值 cos(x):x(弧度)的余弦 fabs(x):求浮点数x的绝对值 ceil(x):求不小于x的最小整数 floor(x):求不大于x ...

  9. cell设置背景颜色为啥不起作用

    利用poi设置背景颜色时,应如下配置, CellStyle cell=workbook.createCellStyle(); cell.setFillForegroundColor(IndexedCo ...

  10. html标签二

    1.没有前后顺序的信息列表<ul> <li></li> <li></li></ul>2.有序列表 <ol>  < ...