usaco2017专题

BZOJ 4756 [Usaco2017 Jan]Promotion Counting dfs序+主席树

Description The cows have once again tried to form a startup company, failing to remember from past experience t hat cows make terrible managers!The cows, conveniently numbered 1…N1…N (1≤N≤100,00

BZOJ4756 - [Usaco2017 Jan]Promotion Counting

Portal Description 给出一个\(n(n\leq10^5)\)个点的带点权的以\(1\)为根的树,求每个点的子树中有多少个权值比该点大的点。 Solution 线段树合并。 我们对于每一个点\(u\),建立一棵线段树保存子树\(u\)中的所有权值。那么\(ans_u\)就等于线段树中比\(val_u\)大的值有多少。而子树\(u\)中的所有权值等于\(u\)的所有子节点的子树中的