传送门

唉蒟蒻又退化了,这道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. UVA1588-Kickdown

    2018-10-30-18:27:03 原题链接 题目描述: 给出两个长度分别为n1,n2且每列高度只为1或2的长条,需要将它们放入一个高度为3的容器,求出能够容纳他们的最短容器长度. 本题思路: 模 ...

  2. matlab基础绘图知识

    axis([xmin xmax ymin ymax])   %设置坐标轴的最小最大值 xlabel('string')                             %标记横坐标 ylabe ...

  3. stark组件之路由分发【模仿Django的admin】

    一.先看下django的admin是如何进行路由分发的 1.先看下django的admin的url路径有哪些 其实很简单,假如有一个书籍表,那么每张表对应四个url,增.删.改.查 查看的url ht ...

  4. swift - label字体 倾斜,加粗

    /* label.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];//加粗 label.font = [UIFont ...

  5. swift - 快速代码块 - 创建 tableview等一些控件 基本属性

    1.创建tableview private lazy var cellId = "cellId" fileprivate lazy var tv : UITableView = { ...

  6. OC 线程操作1 - pthread

    #import "ViewController.h" #import <pthread.h> //1.需要包含这个头文件 @interface ViewControll ...

  7. Hibernate+struct web项目问题总结

    问题一: ClassTable is not mapped [from ClassTable] 解决办法:在添加资源路径 <mapping resource="***/***/***/ ...

  8. supervisor安装、使用详解

    supervisor是用python写的一个进程管理工具,用来启动,重启,关闭进程. 1 supervisor的安装 pip install supervisor 2 supervisor的配置文件( ...

  9. HTML 转 PDF 之 wkhtmltopdf 工具精讲

    术语定义 文档对象 “文档对象”是指PDF文档中的文档对象,共有三种类型的“文档对象”,他们分别是“页面对象”,“封面对象”和“目录对象”. 页面对象 “页面对象”是指以页面的形式在PDF文档中呈现的 ...

  10. Ubuntu 16.04 更换阿里源

    vim /etc/apt/source.list deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by s ...