博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BZOJ4999: This Problem Is Too Simple!树链剖分+动态开点线段树
阅读量:4592 次
发布时间:2019-06-09

本文共 1382 字,大约阅读时间需要 4 分钟。

题目大意:将某个节点的颜色变为x,查询i,j路径上多少个颜色为x的点...

其实最开始一看就是主席树+树状数组+DFS序...但是过不去...MLE+TLE BY FCWWW

其实树剖裸的一批...只是在树剖上套一个动态开点的线段树就可以了...很显然的...就是注意一下细节问题,还有Map这种东西,还是不要乱用的说...

附上代码:

#include 
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define N 100005#define lson l,m,tr[rt].ls#define rson m+1,r,tr[rt].rsstruct edge{int to,next;}e[N<<1];struct node{int ls,rs,siz;}tr[N*40];int rot[N],n,Q,cnt,a[N],head[N],son[N],fa[N],dep[N],siz[N],anc[N],idx[N],tims;void add(int x,int y){e[cnt]=(edge){y,head[x]};head[x]=cnt++;}void Update(int x,int c,int l,int r,int &rt){ if(!rt)rt=++cnt;tr[rt].siz+=c;if(l==r)return ;int m=(l+r)>>1; if(m>=x)Update(x,c,lson);else Update(x,c,rson);}void dfs1(int x,int from){ fa[x]=from,dep[x]=dep[from]+1,siz[x]=1; for(int i=head[x];i!=-1;i=e[i].next) { int to1=e[i].to; if(to1!=from) { dfs1(to1,x);siz[x]+=siz[to1]; if(siz[son[x]]
>1,ret=0; if(L<=m)ret+=query(L,R,lson);if(m
dep[y])swap(x,y); return ret+query(idx[x],idx[y],1,n,rot[c]);}map
mp;int tot=0,S[N],top,b[N];char s[2];int main(){ scanf("%d%d",&n,&Q);memset(head,-1,sizeof(head)); for(int i=1,x;i<=n;i++) { scanf("%d",&x);b[i]=x; if(mp.find(x)==mp.end())mp[x]=++tot; a[i]=mp[x]; }for(int i=1,x,y;i

  

转载于:https://www.cnblogs.com/Winniechen/p/9241850.html

你可能感兴趣的文章
pxe批量装机
查看>>
linux典型应用对系统资源使用的特点
查看>>
linux性能分析工具Procs
查看>>
linux性能分析工具Vmstat
查看>>
linux性能分析工具Memory
查看>>
c# 选择结构
查看>>
c# 委托
查看>>
c# 接口使用
查看>>
c# 事件
查看>>
c# as运算符
查看>>
c# 调试过程
查看>>
c# 结构
查看>>
C# 中的异常处理
查看>>
c# 调试
查看>>
c# 使用序列化
查看>>
c# VS.NET 中的调试工具
查看>>
c# System.Array
查看>>
c# StringBuilder类
查看>>
c# 格式化数据String.Format
查看>>
c# 日期和时间System.DateTime
查看>>