Original link https://www.cnblogs.com/zhouzhendong/p/UOJ30.html
Topic Portal-uoj#30Test Instructions
Uoj write very concise, clear, here will not copy it again.
Solving
First, the Round square tree is built. Next, we call "dot" as the original point, "Square Point" as the new point.
Then just consider online asking how to do it.
---Set the value of the square point to the minimum value of all the points with which he is connected, and then the tree chain is divided into a tree segment of the circle tree to support the interval query.
You will then find that this does not support the modification operation.
--Directly to a Chrysanthemum diagram constantly modify the root node is GG.
So we thought about ways to do it.
We redefine the value of the square point as "the minimum value of the son's weight on the Circle square tree." Then, when asked, the others are the same, but if the LCA is the square point, then add its FA to Min's contribution.
Time Complexity $O (N\log ^2 N) $.
Code
#include <bits/stdc++.h>using namespace Std;typedef long LL; ll read () {ll x=0,f=1;char Ch=getchar (); while (!isdigit (CH) &&ch!= '-') Ch=getchar (); if (ch== '-') f=-1,ch= GetChar (); while (IsDigit (CH)) x= (x<<1) + (x<<3) + (ch^48), Ch=getchar (); return x*f;} const int N=200005,inf=1.1e9;int pr[n],dfn[n],low[n],st[n],time,top,tot;multiset <int> mins[n];vector <int > g[n],g[n];void Tarjan (int x) {low[x]=dfn[x]=++time,st[++top]=x;for (auto y:g[x]) if (!dfn[y]) {Tarjan (y); low[x]= Min (Low[x],low[y]), if (Low[y]>=dfn[x]) {tot++;g[x].push_back (tot); g[tot].push_back (x); int Z;do {z=st[top--];g[z ].push_back (tot); G[tot].push_back (z);} while (z!=y);}} Elselow[x]=min (Low[x],dfn[y]);} namespace Sp{int n,outn;int fa[n],son[n],size[n],depth[n],top[n],p[n],ap[n],cnp=0,val[n];void dfs (int x,int pre,int D {size[x]=1,fa[x]=pre,son[x]=-1,depth[x]=d;for (auto y:g[x]) if (y!=pre) {DFS (y,x,d+1); Size[x]+=size[y];if (son[x]== -1| | SIZE[Y]>SIZE[SON[X]]) son[x]=y;}} void get_top (int x,int tp) {toP[x]=tp;ap[p[x]=++cnp]=x;if (son[x]==-1) return; Get_top (SON[X],TP); for (auto y:g[x]) if (y!=fa[x]&&y!=son[x]) get_top (y,y);} int min[n<<2];void Build (int rt,int l,int R) {if (l==r) return (void) (Min[rt]=val[ap[l]]); int mid= (l+r) >>1, Ls=rt<<1,rs=ls|1;build (Ls,l,mid); build (Rs,mid+1,r); Min[rt]=min (Min[ls],min[rs]);} int query (int rt,int l,int r,int xl,int XR) {if (xl>xr| | l>xr| | R<XL) return inf;if (XL<=L&&R<=XR) return min[rt];int mid= (l+r) >>1,ls=rt<<1,rs=ls|1; return min (Query (LS,L,MID,XL,XR), query (RS,MID+1,R,XL,XR));} void update (int rt,int l,int r,int x,int D) {if (l==r) return (void) (min[rt]=d); int mid= (L+R) >>1,ls=rt<<1,rs= Ls|1;if (x<=mid) update (LS,L,MID,X,D); elseupdate (rs,mid+1,r,x,d); Min[rt]=min (Min[ls],min[rs]);} int query (int a,int b) {int f1=top[a],f2=top[b],ans=inf;while (F1!=F2) {if (Depth[f1]<depth[f2]) swap (F1,F2), swap (A, b); Ans=min (Ans,query (1,1,n,p[f1],p[a)); a=fa[f1],f1=top[a];} if (Depth[a]>depth[b]) swap (A, b); IF (a>outn&&fa[a]!=0) Ans=min (Ans,query (1,1,n,p[fa[a]],p[fa[a])); return min (Ans,query (1,1,n,p[a],p[b)) );}} int main () {int n=tot=read (), M=read (), Q=read (), for (Int. i=1;i<=n;i++) Pr[i]=read (); for (int i=1;i<=m;i++) {int a= Read (), B=read (); G[a].push_back (b); G[b].push_back (a);} Tarjan (1); SP:: Dfs (1,0,0), SP:: Get_top (P), for (int i=n+1;i<=tot;i++) Mins[i].insert (INF), for (int i=1;i<=n;i+ +) MINS[SP:: Fa[i]].insert (Pr[i]), for (int i=1;i<=n;i++) SP:: val[i]=pr[i];for (int i=n+1;i<=tot;i++) SP:: val[i]= *mins[i].begin (); SP:: Build (1,1,SP:: N=tot); SP:: Outn=n;while (q--) {char s[10];scanf ("%s", s), int x=read (), Y=read (); if (s[0]== ' A ') printf ("%d\n", SP:: Query (x, y)), else {int F=SP:: fa[x];if (f) {mins[f].erase (Mins[f].find (pr[x])); Mins[f].insert (pr[x]=y); SP:: Update (1,1,SP:: n,sp:: P[f],*mins[f].begin ());} SP:: Update (1,1,SP:: n,sp:: P[x],y);}} return 0;}
Uoj#30/codeforces 487E Tourists point dual connected components, Tarjan, round square tree, tree chain, segment tree