这为啥会 MLE
查看原帖
这为啥会 MLE
501947
DengDuck鄧德楼主2024/4/14 21:43

二周目玩家,不理解为啥

一周目没遇到啊

#include<bits/stdc++.h>
#define LL int
#define Ls(x) t[x].Lson
#define Rs(x) t[x].Rson
using namespace std;
const LL N=1e5+5;
const LL Mod=20090327;
const LL P=29;
LL n,m,Pw[N],rt;
char c[N];
LL tot;
struct Tr
{
	LL Lson,Rson,Sz,Hsh,P,v;
}t[N];
inline LL Make(LL x)
{
	t[++tot]={0,0,1,x,rand(),x};
	return tot;
}
inline void Up(LL x)
{
	if(!x)return;
	LL t1=(long long)t[Ls(x)].Hsh*Pw[1+t[Rs(x)].Sz]%Mod;
	LL t2=(long long)Pw[t[Rs(x)].Sz]*t[x].v;
	t[x].Hsh=(t1+t2+t[Rs(x)].Hsh)%Mod;
	t[x].Sz=t[Ls(x)].Sz+t[Rs(x)].Sz+1;
	//	cout<<"Sz"<<x<<' '<<t[x].Sz<<endl;
}
void Spl(LL rt,LL &x,LL &y,LL v)
{
	if(!rt)x=y=0;
	else
	{
		if(t[rt].Sz<=v)x=rt,y=0;
		else if(v==0)x=0,y=rt;
		else if(t[Ls(rt)].Sz+1<=v)x=rt,Spl(Rs(rt),Rs(rt),y,v-t[Ls(rt)].Sz-1);
		else y=rt,Spl(Ls(rt),x,Ls(rt),v);
		Up(rt);
	}
}
void Mrg(LL &rt,LL x,LL y)
{
	if(!x||!y)rt=x+y;
	else
	{
		if(t[x].P<t[y].P)rt=x,Mrg(Rs(rt),Rs(rt),y);
		else rt=y,Mrg(Ls(rt),x,Ls(rt));
		Up(rt);
	}
}
inline LL gt(LL x,LL y)
{
	LL rt1,rt2,rt3;
	Spl(rt,rt1,rt3,y);
	Spl(rt1,rt1,rt2,x-1);
	LL T=t[rt2].Hsh;
	//	cout<<x<<' '<<y<<' '<<T<<' '<<t[rt2].Sz<<endl;
	Mrg(rt1,rt1,rt2),Mrg(rt,rt1,rt3);
	
	return T;
}
inline LL Gt(LL x,LL y)
{
	LL l=1,r=t[rt].Sz-max(x,y)+1,Ans=0;
	while(l<=r)
	{
		LL Mid=(l+r)/2;
		if(gt(x,x+Mid-1)==gt(y,y+Mid-1))Ans=Mid,l=Mid+1;
		else r=Mid-1;
	}
	return Ans;
}
char op[30],s[30];
int main()
{
	Pw[0]=1;
	for(int i=1;i<N;i++)Pw[i]=(long long)Pw[i-1]*P%Mod;
	scanf("%s",c+1);
	n=strlen(c+1);
	for(int i=1;i<=n;i++)Mrg(rt,rt,Make(c[i]-'a'));
	scanf("%d",&m);
	while(m--)
	{
		
		
		scanf("%s",op);
		//	cout<<"M"<<m<<' '<<op<<endl;
		if(op[0]=='Q')
		{
			LL x,y;
			scanf("%d%d",&x,&y);
			printf("%d\n",Gt(x,y));
		}
		if(op[0]=='R')
		{
			LL x;
			scanf("%d %s",&x,s);
			LL rt1,rt2,rt3;
			Spl(rt,rt1,rt3,x);
			Spl(rt,rt1,rt2,x-1);
			t[rt2].Hsh=s[0]-'a';
			t[rt2].v=s[0]-'a';
			Mrg(rt1,rt1,rt2),Mrg(rt,rt1,rt3);
		}
		if(op[0]=='I')
		{
			LL x;
			scanf("%d %s",&x,s);
			LL rt1,rt2;
			Spl(rt,rt1,rt2,x);
			Mrg(rt1,rt1,Make(s[0]-'a')),Mrg(rt,rt1,rt2);
		}		
	}
	return 0;
}
//RP++
2024/4/14 21:43
加载中...