题意:问你最多每一个子树当中,出现次数最多的颜色的编号之和。
解:线段树合并
#include <bits/stdc++.h>
#define en '\n'
#define Swt signed main
using namespace std;
typedef long long ll;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int maxn=1e5+10;
const int maxm=(1e5+10)*67;
int rd(){int tem;scanf("%d",&tem);return tem;}
int a[maxn];
int ls[maxm],rs[maxm],rt[maxn];
ll ans[maxm],sm[maxm];
ll tot,n,que[maxn];
int dfn;
struct node{
int v,nxt;
}edge[maxn<<1];
int head[maxn];
int cnt=0;
void add(int x,int y){
edge[++cnt]=(node){y,head[x]};head[x]=cnt;
}
void up(int x){
int lson=ls[x],rson=rs[x];
if(sm[lson]==sm[rson]){
sm[x]=sm[lson];
ans[x]=ans[lson]+ans[rson];
}
else if(sm[lson]>sm[rson]){
sm[x]=sm[lson];
ans[x]=ans[lson];
}
else {
sm[x]=sm[rson];
ans[x]=ans[rson];
}