博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
P2633 Count on a tree
阅读量:6956 次
发布时间:2019-06-27

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

思路

运用树上差分的思想,转化成一个普通的主席树模型即可求解

代码

#include 
#include
#include
using namespace std;struct Node{ int lson,rson,sz;}pt[100100*30];const int MAXlog=19;int dep[100100],jump[100100][MAXlog],lastans=0,n,m,u[100100<<1],Nodecnt,v[100100<<1],w_p[100100],ax[100100],nx,fir[100100],nxt[100100<<1],cnt,root[100100];void addedge(int ui,int vi){ ++cnt; u[cnt]=ui; v[cnt]=vi; nxt[cnt]=fir[ui]; fir[ui]=cnt;}void insert(int L,int R,int pos,int &o){ pt[++Nodecnt]=pt[o]; o=Nodecnt; pt[o].sz++; if(L==R) return; int mid=(L+R)>>1; if(pos<=mid) insert(L,mid,pos,pt[o].lson); else insert(mid+1,R,pos,pt[o].rson);}int lca(int x,int y){ if(dep[x]
=0;i--) if(dep[x]-(1<
=dep[y]) x=jump[x][i]; if(x==y) return x; for(int i=MAXlog-1;i>=0;i--) if(jump[x][i]!=jump[y][i]) x=jump[x][i],y=jump[y][i]; return jump[x][0];}int query(int L,int R,int k,int rootx,int rooty,int rootlca,int falca){ if(L==R) return L; int lch=pt[pt[rootx].lson].sz+pt[pt[rooty].lson].sz-pt[pt[rootlca].lson].sz-pt[pt[falca].lson].sz; int mid=(L+R)>>1; if(lch

转载于:https://www.cnblogs.com/dreagonm/p/10198849.html

你可能感兴趣的文章
理解js对象
查看>>
2017-10-07 前端日报
查看>>
发展至今的机器学习到底对我们的就业和社会产生了哪些影响?
查看>>
2017四川电商年度盛典,千机网论道企业变革
查看>>
四种方法教你破解Linux(CentOS7.4)系统的root密码
查看>>
用数据分析赢得卓越业务
查看>>
java直接执行jar包
查看>>
Java中的正则表达式
查看>>
区块链应用 | 2018年,区块链将有这五大新发展
查看>>
亚信安全:2017年勒索软件与商业邮件欺骗将继续蔓延
查看>>
eclipse开发web应用程序步骤(图解)
查看>>
GitHub上不错的Android开源项目(三)
查看>>
Nginx内置状态信息(http_stub_status)
查看>>
[MySQL TroubleShooting] 服务启动报错
查看>>
斑马技术邀您吃生鲜——以极速物流方案让您领鲜一步
查看>>
Linux系统目录结构
查看>>
一键系统维护工具 v 1.9
查看>>
变量替换删除企业应用场景
查看>>
XenApp/XenDesktop 7.11新功能
查看>>
全面降低windows系统的安全隐患(一)[Web安全大家谈]
查看>>