bzoj許可權題,洛谷題面
樹上帶修改主席樹
貌似和cou
nton
atre
e 那題很相似呀
只需要套上乙個樹狀陣列來維護修改好就好了
但是記住是用df
s 來記錄主席樹的標號
一定不要搞錯了
每一次修改只會影響他子數的值 而在d
fs序上就是連續的一段
美滋滋的做完了
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using
namespace
std;
#define ll long long
#define rg register
#define max 161000
inline
int read()
struct linee[max<<1];
int h[max],cnt=1;
inline
void add(int u,int v);h[u]=cnt++;}
int dfn[max],low[max],fa[max],size[max],hson[max],dep[max],top[max];
int tim,n,q;
int s[max<<1],tot,tt[max];
int lowbit(int x)
struct nodet[max<<8];
int rt[max],tot,ln[max];
int lca(int u,int v)
void premodify(int k,int pos,int w)
int tmp1[max<<1],tmp2[max<<1],t1,t2;
int query(int l,int r,int k)
else
}int prequery(int u,int v,int k)
void dfs1(int u,int ff)
}void dfs2(int u,int tp)
low[u]=tim;
}void dfs3(int u,int ff)
struct opo[max];
int main()
for(int i=1;i<=q;++i)o[i].k=read(),o[i].a=read(),o[i].b=read();
for(int i=1;i<=q;++i)if(o[i].k==0)s[++tot]=o[i].b;
sort(&s[1],&s[tot+1]);
tot=unique(&s[1],&s[tot+1])-s-1;
for(int i=1;i<=n;++i)tt[i]=lower_bound(&s[1],&s[tot+1],tt[i])-s;
for(int i=1;i<=q;++i)if(o[i].k==0)o[i].b=lower_bound(&s[1],&s[tot+1],o[i].b)-s;
dfs1(1,0);dfs2(1,1);dfs3(1,1);
for(int i=1;i<=q;++i)
else
printf("%d\n",s[prequery(o[i].a,o[i].b,o[i].k)]);}}
return
0;
}
bzoj1146 網路管理
發現是鏈上的問題,所以樹鏈剖分 發現要查詢第k大,因為第k大不支援合併,所以要二分答案 二分答案後相當於詢問一些區間內大於某數的數個數,直接線段樹套平衡樹即可 時間複雜度 o nlog n 跟 o n 有什麼區別 可以卡過 1 include2 using namespace std 3 defin...
BZOJ1146 網路管理,整體二分
傳送門 logn 查詢時二分答案,查詢路徑上重鏈中的平衡樹,複雜度 log3n 總複雜度o nlogn qlog3n log2n 查詢時把 log 個主席樹放在一起查做到 log2n 感謝lucida的提醒 總複雜度o nlog2n qlog2n o q n23logn log2n 基本過不了,離線...
BZOJ1146 CTSC2008 網路管理
樹狀陣列與線段樹 題目傳送門 在尤拉序上用樹狀陣列套權值線段樹搞事情。在進的時候加一,出去的時候減一。從尤拉序第一位到當前點的 l 就是根到當前點的狀態 因為其他的路徑一進一出抵消掉了 然後你求出兩個點的 lca 和 lca 的父親減一減跑一跑就好了。時間複雜度 o nlog 2n 空間複雜度 o ...