#include<cstdio> #include<iostream> #define M 1000006 #define N 1000006 using namespace std; ],f1[N],cnt,dui[N],lian[N],tim,l1,l2; int r1; struct data { int l,r,sum,tag; }shu[*N]; void jia(int a1,int a2) { cnt++; next[cnt]=head[a1]; head[a1]=c…
题解: 树剖,线段树维护区间颜色段数 记录两端点的颜色,做到O(1)合并 问题: 非递归建树实现 #include<iostream> #include<cstdio> #include<cstring> using namespace std; ; int n,m; int incolor[maxn]; int cntedge; int head[maxn]; ],nex[maxn<<]; int addedge(int x,int y){ nex[++c…
#include <cstdio> #include <cstring> #include <cstdlib> using namespace std; const int N=100001; int n,m,color[N]; //Basic struct G { int v,nxt; }map[N+N]; int hd[N],tt; //Graph int son[N],dep[N],pre[N],size[N]; int tid[N],top[N],num; //…