博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
P4175 [CTSC2008]网络管理
阅读量:6881 次
发布时间:2019-06-27

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

题意分析

带修改树链第\(k\)

首先我们使用树链剖分将树上问题转化为区间问题

然后对于当前修改 我们直接修改即可

对于链上第\(k\)大 我们先求一个总点数

转化为链上第\(k\)

然后我们将\(x\)\(y\)之间所有的重链都提出来

那么在\(dfs\)序上就是一堆连续区间

而且最多\(log\)

类比于区间问题维护一个区间

我们顶多维护\(log\)个区间

然后同时跳即可 详细见代码即可

CODE:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long#define inf 0x7fffffff#define N 80008#define IL inline#define M 1008611#define D double#define ull unsigned long long#define R registerusing namespace std;template
IL void read(T &_){ T __=0,___=1;char ____=getchar(); while(!isdigit(____)) {if(____=='-') ___=0;____=getchar();} while(isdigit(____)) {__=(__<<1)+(__<<3)+____-'0';____=getchar();} _=___ ? __:-__;}/*-------------OI使我快乐-------------*/int n,m,tot,cnt,all;struct Node{ int fro,tox,cnta,cntb; int cdy[30],wzy[30];}e[N];struct Qury{ int k,a,b;}ex[N];int num[N],res[N<<1];int to[N<<1],nex[N<<1],head[N];int dep[N],fa[N],ssiz[N],son[N];int top[N],dfn[N],wt[N];int root[N],lson[M*40],rson[M*40],siz[M*40];IL void add(int x,int y){to[++tot]=y;nex[tot]=head[x];head[x]=tot;}IL int get_hash(int x){return lower_bound(res+1,res+cnt+1,x)-res;}IL void insert(int &now,int le,int ri,int pos,int d){ if(!now) now=++tot;siz[now]+=d; if(le==ri) return; int mid=(le+ri)>>1; if(pos<=mid) insert(lson[now],le,mid,pos,d); else insert(rson[now],mid+1,ri,pos,d);}IL void Add(int x,int pos,int d){ for(R int i=x;i<=n;i+=i&-i) insert(root[i],1,cnt,pos,d);}IL void get_ready(){ for(R int i=1;i<=all;++i) { e[i].cnta=0;e[i].cntb=0; for(R int j=e[i].fro-1;j>0;j-=j&-j) e[i].cdy[++e[i].cnta]=root[j]; for(R int j=e[i].tox;j>0;j-=j&-j) e[i].wzy[++e[i].cntb]=root[j]; }}IL void dfs1(int now,int fat){ dep[now]=dep[fat]+1;fa[now]=fat;ssiz[now]=1; int maxsiz=-1; for(R int i=head[now];i;i=nex[i]) { int v=to[i]; if(v==fat) continue; dfs1(v,now); ssiz[now]+=ssiz[v]; if(ssiz[v]>maxsiz) maxsiz=siz[v],son[now]=v; }}IL void dfs2(int now,int topf){ top[now]=topf;dfn[now]=++all;wt[all]=now; if(!son[now]) return;dfs2(son[now],topf); for(R int i=head[now];i;i=nex[i]) { int v=to[i]; if(v==fa[now]||v==son[now]) continue; dfs2(v,v); }}IL int LCA(int nowx,int nowy){ while(top[nowx]!=top[nowy]) { if(dep[top[nowx]]
dep[nowy]) swap(nowx,nowy); return nowx;}IL void QuryRange(int nowx,int nowy){//我们提出所有的dfs序的连续区间 while(top[nowx]!=top[nowy]) { if(dep[top[nowx]]
dep[nowy]) swap(nowx,nowy); ++all;e[all].fro=dfn[nowx];e[all].tox=dfn[nowy]; return;}IL int getsiz(int x,int y){ int lca=LCA(x,y); return dep[x]+dep[y]-dep[lca]-dep[fa[lca]];}IL int getsum(){//类似于动态主席树 int res=0; for(R int i=1;i<=all;++i) { for(R int j=1;j<=e[i].cnta;++j) res-=siz[lson[e[i].cdy[j]]]; for(R int j=1;j<=e[i].cntb;++j) res+=siz[lson[e[i].wzy[j]]]; } return res;}IL void pushcdy(){ for(R int i=1;i<=all;++i) { for(R int j=1;j<=e[i].cnta;++j) e[i].cdy[j]=lson[e[i].cdy[j]]; for(R int j=1;j<=e[i].cntb;++j) e[i].wzy[j]=lson[e[i].wzy[j]]; }}IL void pushwzy(){ for(R int i=1;i<=all;++i) { for(R int j=1;j<=e[i].cnta;++j) e[i].cdy[j]=rson[e[i].cdy[j]]; for(R int j=1;j<=e[i].cntb;++j) e[i].wzy[j]=rson[e[i].wzy[j]]; }}IL int getrnk(int le,int ri,int k){ while(le
>1; int tmp=getsum(); if(k<=tmp) ri=mid,pushcdy(); else k-=tmp,le=mid+1,pushwzy(); } return le;}int main(){// freopen("222.in","r",stdin);// freopen("222.out","w",stdout); read(n);read(m); for(R int i=1;i<=n;++i) read(num[i]),res[++cnt]=num[i]; for(R int i=1,x,y;i

HEOI 2019 RP++

转载于:https://www.cnblogs.com/LovToLZX/p/10650882.html

你可能感兴趣的文章
『AngularJS』创建 Service
查看>>
linux 修改桌面背景
查看>>
Quick Test Professional(UFT)Web Service 测试入门
查看>>
Ubuntu上手动安装sbt
查看>>
facebook首席运营谈成功经验
查看>>
资本倍增
查看>>
DataQL 的表达式编译(自创的一种表达式编译算法)
查看>>
9.29PMP每日一题
查看>>
ORACLE 学习笔记1
查看>>
vmware格式转换
查看>>
beego mysql in查询
查看>>
git 回退版本
查看>>
go mod 在使用私有gitlab时“go-get=1”错误解决
查看>>
Tableau Server 9.1.2 配置集群手册
查看>>
java逻辑运算符
查看>>
org.bson.codecs.configuration.CodecConfigurationException
查看>>
jsoup抓取网页+详细讲解
查看>>
Python实现修改Windows CMD命令行输出颜色(完全解析)
查看>>
HQL语句讲解
查看>>
服务器安全狗linux版 V2.4 发布 增加网页木马扫描
查看>>