[Luogu4230]???????????????

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Luogu4230]???????????????相关的知识,希望对你有一定的参考价值。

???????????????   markdown   new   algorithm   root   body   ??????   ??????   http   

????????????

sol

?????????+????????????????????????????????????????????????????????????qaq???
LCT
???????????????\(i\)??????????????????????????????\(j\)???????????????????????????????????????\([i,j],[i,j+1]...[i,m]\)??????????????????????????????????????????\([i,j]\)????????????\(m-j+1\)?????????\([j+1,m]\)???????????????????????????\(m-j,m-j-1...1\)
???????????????????????????????????????????????????????????????

?????????????????????????????????

???????????????O(nlogn) ???????????????100??????????????????75~100???
FAQ?????????????????????LCT????????????75???/90???
A?????????findroot??????splay???????????????????????????splay??????????????????O(n^2)??????

????????????????????????LCT???????????????findroot???splay??????????????????

code

#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 1000005;
int gi()
{
    int x=0,w=1;char ch=getchar();
    while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if (ch=='-') w=0,ch=getchar();
    while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return w?x:-x;
}
int m,u[N],v[N],o[N<<1],fa[N],ch[2][N],rev[N],Stack[N],top,t1[N],t2[N];
bool son(int x){return x==ch[1][fa[x]];}
bool isroot(int x){return x!=ch[0][fa[x]]&&x!=ch[1][fa[x]];}
void reverse(int x){if(!x)return;swap(ch[0][x],ch[1][x]);rev[x]^=1;}
void pushdown(int x){if(!rev[x])return;reverse(ch[0][x]);reverse(ch[1][x]);rev[x]=0;}
void rotate(int x)
{
    int y=fa[x],z=fa[y],c=son(x);
    ch[c][y]=ch[c^1][x];if (ch[c][y]) fa[ch[c][y]]=y;
    fa[x]=z;if (!isroot(y)) ch[son(y)][z]=x;
    ch[c^1][x]=y;fa[y]=x;
}
void splay(int x)
{
    Stack[top=1]=x;
    for (int y=x;!isroot(y);y=fa[y]) Stack[++top]=fa[y];
    while (top) pushdown(Stack[top--]);
    for (int y=fa[x];!isroot(x);rotate(x),y=fa[x])
        if (!isroot(y)) son(x)^son(y)?rotate(x):rotate(y);
}
void access(int x){for (int y=0;x;y=x,x=fa[x]) splay(x),ch[1][x]=y;}
void makeroot(int x){access(x);splay(x);reverse(x);}
int findroot(int x){access(x);splay(x);while(ch[0][x])x=ch[0][x];splay(x);return x;}
void split(int x,int y){makeroot(x);access(y);splay(y);}
void link(int x,int y){makeroot(x);fa[x]=y;}
void cut(int x,int y){split(x,y);ch[0][y]=fa[x]=0;}
int main()
{
    m=gi();
    for (int i=1;i<=m;++i) u[i]=gi(),v[i]=gi();
    for (int i=1,j=1;i<=m;cut(u[i],v[i]),++i)
    {
        while (j<=m&&findroot(u[j])!=findroot(v[j])) link(u[j],v[j]),++j;
        if (j<=m) t1[i]+=m-j+1,t2[j+1]--;
    }
    for (int i=1;i<=m;++i) t2[i]+=t2[i-1];
    for (int i=1;i<=m;++i) t1[i]+=t1[i-1],t2[i]+=t2[i-1];
    for (int i=1;i<=m;++i) printf("%d ",t1[i]+t2[i]);
    return 0;
}

以上是关于[Luogu4230]???????????????的主要内容,如果未能解决你的问题,请参考以下文章

bzoj4230: 倒计时

JZOJ 4230. 淬炼神体 (Standard IO)

Data too long for column 'pay_channel' at row 1

Pandas 随机加权选择

Pandas 随机加权选择

大学生数学竞赛试题荟萃