如何用缠论可视化解决技术分析痛点?3个步骤开启量化交易新体验——基于TradingView本地SDK的零门槛解决方案

核心内容摘要

信息论与编码篇---马氏距离
零门槛搭建全平台游戏串流服务器:Sunshine从部署到优化完全指南

掌握程序化建模:从参数调节到星际场景的科幻创作之旅

F. Unique Occurrencestime limit per test: 6 secondsmemory limit per test: 1024 megabytesinput: standard inputoutput: standard outputYou are given a tree, consisting ofnnnvertices. Each edge has an integer value written on it.Letf(v,u)f(v, u)f(v,u)be the number of values that appearexactly onceon the edges of a simple path between verticesvvvanduuu.Calculate the sum off(v,u)f(v, u)f(v,u)over all pairs of verticesvvvanduuusuch that1≤vu≤n1 \le v u \le n1≤vu≤n.DeepL 翻译:给你一棵由nnn个顶点组成的树。

每条边上都写有一个整数值。

假设f(v,u)f(v,u)f(v,u)是顶点vvv和uuu之间简单路径的边上只出现一次的值的个数。

计算所有顶点vvv和uuu之间的f(v,u)f(v,u)f(v,u)和1≤vu≤n1 ≤ v u ≤ n1≤vu≤n。

把每种颜色看为时间轴上的事件进行分治处理。

简单来讲我们用线段树分治对于每种颜色全部删除后的树上的 dsu 进行统计很显然此时某一条边的贡献就是 左右两个连通块的大小的乘积然后再把这种颜色的边加回来再进行下一条边的枚举。

总的复杂度只有 n log nvectortupleint,int,inte;vectorvectorPIIcol;intans;structop{intt,a,b;};classDSU{public:vectorintf,siz;stackopsave;DSU(){}DSU(intn){init(n);}voidinit(intn){f.resize(n

;iota(range(f),

;siz.assign(n1,

;}intfind(intx){returnf[x]x?x:find(f[x]);}boolsame(intx,inty){returnfind(x)find(y);}boolmerge(intx,inty){xfind(x);yfind(y);if(xy){return0;}if(siz[x]siz[y]){swap(x,y);}save.push({1,x,y});siz[y]siz[x];f[x]y;returntrue;}voidrollback(){auto[t,x,y]save.top();save.pop();if(t

{siz[y]-siz[x];f[x]x;}else{}}size_tgetSnapshot()const{returnsave.size();}voidroll(inttar){while(save.size()tar){rollback();}}intsize(intx){returnsiz[find(x)];}};templatetypenameTclassSegmentTreeDC{public:inttot;// 时间点数叶子数量vectorvectorTtr;// 每个节点的操作列表SegmentTreeDC():tot(0LL){}SegmentTreeDC(int_T){init(_T);}voidinit(int_T){totmax(1LL,_T);tr.clear();tr.resize(4LL*(tot

);}// 插入一个操作 op 到闭区间 [l, r]voidinsert(intp,intL,intR,intl,intr,constTop){if(lr||lR||rL)return;if(lLRr){tr[p].push_back(op);return;}intmidLR1;insert(p1,L,mid,l,r,op);insert(p1|1,mid1,R,l,r,op);}voidinsert(intl,intr,constTop){if(lr)return;insert(1,1,tot,l,r,op);}voiddfs(DSUdsu){functionvoid(int,int,int)dfs[](intp,intl,intr){size_t snapdsu.getSnapshot();for(autoe:tr[p]){dsu.merge(e.first,e.second);}if(lr){for(auto[u,v]:col[l]){ansdsu.size(u)*dsu.size(v);}}else{intmid(lr)1;dfs(p1,l,mid);dfs(p1|1,mid1,r);}dsu.roll(snap);};dfs(1,1,tot);}};voidsolve(){intn;cinn;e.resize(n

;col.resize(n

;for(inti1;in;i){intu,v,w;cinuvw;e[i]{u,v,w};col[w].push_back({u,v});}DSUdsu(n);SegmentTreeDCPIIseg(n);for(inti1;in;i){auto[u,v,w]e[i];seg.insert(1,w-1,{u,v});seg.insert(w1,n,{u,v});}seg.dfs(dsu);coutansendl;}signedmain(){cin.tie(nullptr)-ios::sync_with_stdio(false);intT1;// cin T;for(;T_T;T_)solve();return0;}

大理宝藏库17C-大理宝藏库应用

百度百家号客服电话人工服务

123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123