题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4756 合并子树的权值线段树: merge 返回 int 或者是 void 都可以. 代码如下: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define mid ((l+r)>>1) using namespace std; ,xm=x…
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4756 线段树合并裸题.那种返回 int 的与传引用的 merge 都能过.不知别的题是不是这样. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ,M=N**; int n,m,a[N],tp[N],rt[N],…
题目描述 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,000), organize t he company as a tree, with cow 1 as the preside…
题意 题目链接 Sol 线段树合并板子题 #include<bits/stdc++.h> using namespace std; const int MAXN = 400000, SS = MAXN * 21; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >=…
Description n只奶牛构成了一个树形的公司,每个奶牛有一个能力值pi,1号奶牛为树根. 问对于每个奶牛来说,它的子树中有几个能力值比它大的. Input n,表示有几只奶牛 n<=100000 接下来n行为1-n号奶牛的能力值pi 接下来n-1行为2-n号奶牛的经理(树中的父亲) Output 共n行,每行输出奶牛i的下属中有几个能力值比i大 Sample Input 5 804289384 846930887 681692778 714636916 957747794 1 1 2 3…
题目链接 \(Description\) 有n个座山,其高度为hi.有m条带权双向边连接某些山.多次询问,每次询问从v出发 只经过边权<=x的边 所能到达的山中,第K高的是多少. \(Solution\) x的限制将图分成了若干连通块,如果x单调递增的话,只需要合并连通块就可以了. 离线,并查集维护所属连通块,线段树合并状态.查询K大.(强制在线的话可以主席树?BZOJ3551 不想写了还是写了,还好) 强制在线的Kruskal+主席树做法:BZOJ3551. //39360kb 5248ms…
4631: 踩气球 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 265  Solved: 136[Submit][Status][Discuss] Description 六一儿童节到了, SHUXK 被迫陪着M个熊孩子玩一个无聊的游戏:有N个盒子从左到右排成一排,第i个盒子里装着Ai个气球. SHUXK 要进行Q次操作,每次从某一个盒子里拿出一个没被踩爆的气球,然后熊孩子们就会立刻把它踩爆. 这M个熊孩子每个人都指定了一个盒子区间[Li, R…
5457: 城市 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 18  Solved: 12[Submit][Status][Discuss] Description 有n座城市,m个民族.这些城市之间由n-1条道路连接形成了以城市1为根的有根树.每个城市都是某一民族的聚居 地,Master知道第i个城市的民族是A_i,人数是B_i.为了维护稳定,Master需要知道某个区域内人数最多的民族 .他向你提出n个询问,其中第i个询问是:求以i为根的子…
题面:P3605 [USACO17JAN]Promotion Counting晋升者计数 题解:这是一道万能题,树状数组 || 主席树 || 线段树合并 || 莫队套分块 || 线段树 都可以写..记得离散化 线段树合并版: #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; ; ,edge_head[maxn],W[ma…
题目传送门 Promotion Counting 题目描述 The cows have once again tried to form a startup company, failing to remember from past experience that cows make terrible managers! The cows, conveniently numbered 1 \ldots N1…N (1 \leq N \leq 100,0001≤N≤100,000), organ…