线性空间MLE玄学
查看原帖
线性空间MLE玄学
372708
Yahbim楼主2021/9/8 21:22

LCT板子题,这都能莫名其妙MLE两个点。链接

最离谱的是,我在主函数最开头加了个printf,按理说一开始就会WA掉,但还是MLE,绝了。链接

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int read(){
    int res=0;char ch=getchar();
    while(!isdigit(ch)) ch=getchar();
    while(isdigit(ch)) res=res*10+ch-'0',ch=getchar();
    return res;
}

int n,m,a[N];

struct LCT{
#define isroot(u) (son[fa[u]][0]!=u&&son[fa[u]][1]!=u)
#define ls (son[u][0])
#define rs (son[u][1])
    int fa[N],son[N][2],rev[N],siz[N];
    void pushup(int u){siz[u]=siz[ls]+siz[rs]+1;}
    void pushdown(int u){if(rev[u]) rev[ls]^=1,rev[rs]^=1,rev[u]=0,swap(ls,rs);}
    void update(int u){if(!isroot(u)) update(fa[u]);pushdown(u);}
    void rotate(int u){
	int v=fa[u],fav=fa[v],w=son[v][1]==u;
	if(!isroot(v)) son[fav][son[fav][1]==v]=u;
	son[v][w]=son[u][!w],son[u][!w]=v;
	fa[son[v][w]]=v,fa[u]=fav,fa[v]=u;
	pushup(v),pushup(u);
    }
    void splay(int u){
	update(u);
	for(int v=fa[u];!isroot(u);rotate(u),v=fa[u])
	    if(!isroot(v)) rotate(son[fa[v]][1]==v^son[v][1]==u?u:v);
    }
    void access(int u){
	for(int tmp=0;u;tmp=u,u=fa[u])
	    splay(u),rs=tmp,pushup(u);
    }
    void makeroot(int u){access(u),splay(u),rev[u]^=1;}
    void split(int u,int v){makeroot(u),access(v),splay(v);}
    void link(int u,int v){makeroot(u),fa[u]=v;}
    void cut(int u,int v){split(u,v),son[v][0]=fa[u]=0;}
}tr;

int main(){
    n=read();
    for(int i=1;i<=n;++i) a[i]=read(),tr.link(i,i+a[i]>n?n+1:i+a[i]);
    m=read();
    for(int i=1,opt,p,w;i<=m;++i){
	opt=read(),p=read()+1;
	if(opt==1) tr.split(n+1,p),printf("%d\n",tr.siz[p]-1);
	else w=read(),tr.cut(p,p+a[p]),a[p]=w,tr.link(p,p+a[p]>n?n+1:p+a[p]);
    }
    return 0;
}
2021/9/8 21:22
加载中...