Distance Statistics Description Frustrated at the number of distance queries required to find a reasonable route for his cow marathon, FJ decides to ask queries from which he can learn more information. Specifically, he supplies an integer K (1 <…
统计在一个root下的两个子树,每个子树都和前面的运算一下再加进去对于这种需要排序的运算很麻烦,所以考虑先不去同子树内点对的算出合法点对个数,然后减去每一棵子树内的合法点对(它们实际上是不合法的,相当于一个容斥) 算点对用排序+双指针即可 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N=1000005; int n,m,h[N],cnt,rt…