玄关求调块链40pts
查看原帖
玄关求调块链40pts
748694
yinianxingkong楼主2024/1/19 12:15

rt,注释掉insert里面的split并开大数组就可以AC(显然数据蒻了),但是真的不知道错在哪里了……

#include<bits/stdc++.h>
//#define int long long
using namespace std;
namespace fast_IO {
#define IOSIZE 100000
int precision=3,POW[10]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};char ibuf[IOSIZE],obuf[IOSIZE],*p1=ibuf,*p2=ibuf,*p3=obuf;
#ifdef ONLINE_JUDGE
#define getchar() ((p1==p2)and(p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin),p1==p2)?(EOF):(*p1++))
#define putchar(x) ((p3==obuf+IOSIZE)&&(fwrite(obuf,p3-obuf,1,stdout),p3=obuf),*p3++=x)
#define isdigit(ch) (ch>47&&ch<58)
#define isspace(ch) (ch<33)
#endif
template<typename T>inline T read(){T s=0;int w=1;char ch;while(ch=getchar(),!isdigit(ch)&&(ch!=EOF))if(ch==45)w=-1;if(ch==EOF)return 0;while(isdigit(ch))s=s*10+ch-48,ch=getchar();return s*w;}template<typename T>inline bool read(T&s){s=0;int w=1;char ch;while(ch=getchar(),!isdigit(ch)&&(ch!=EOF))if(ch==45)w=-1;if(ch==EOF)return 0;while(isdigit(ch))s=s*10+ch-48,ch=getchar();return s*=w,1;}inline bool read(char&s){while(s=getchar(),isspace(s));return 1;}inline bool read(char*s){char ch;while(ch=getchar(),isspace(ch));if(ch==EOF)return 0;while(!isspace(ch))*s++=ch,ch=getchar();*s='\000';return 1;}template<typename T>inline void print(T x){if(x<0)putchar(45),x=-x;if(x>9)print(x/10);putchar(x%10+48);}inline void print(char x){putchar(x);}inline void print(char*x){while(*x)putchar(*x++);}inline void print(const char*x){for(int i=0;x[i];i++)putchar(x[i]);}inline bool read(std::string&s){s="";char ch;while(ch=getchar(),isspace(ch));if(ch==EOF)return 0;while(!isspace(ch))s+=ch,ch=getchar();return 1;}inline void print(std::string x){for(int i=0,n=x.size();i<n;i++)putchar(x[i]);}inline bool read(bool&b){char ch;while(ch=getchar(),isspace(ch));b=ch^48;return 1;}inline void print(bool b){putchar(b+48);}inline bool read(double&x){int a=0,b=0;char ch=getchar();bool f=0;while(ch<48||ch>57){if(ch==45)f=1;ch=getchar();}while(47<ch&&ch<58){a=(a<<1)+(a<<3)+(ch^48);ch=getchar();}if(ch!=46){x=f?-a:a;return 1;}ch=getchar();while(47<ch&&ch<58){b=(b<<1)+(b<<3)+(ch^48),ch=getchar();}x=b;while(x>1)x/=10;x=f?-a-x:a+x;return 1;}inline void print(double x){if(x<0){putchar(45),x=-x;}x=round((long double)x*POW[precision])/POW[precision],print((long long)x),putchar(46),x-=(long long)(x);for(int i=1;i<=precision;i++)x*=10,putchar(x+48),x-=(int)x;}template<typename T,typename...T1>inline int read(T& a,T1&...other){return read(a)+read(other...);}template<typename T,typename...T1>inline void print(T a,T1...other){print(a),print(other...);}struct Fast_IO{~Fast_IO(){fwrite(obuf,p3-obuf,1,stdout);}}io;template<typename T>Fast_IO& operator>>(Fast_IO&io,T&b){return read(b),io;}template<typename T>Fast_IO& operator<<(Fast_IO&io,T b){return print(b),io;}
#define cout io
#define cin io
#define endl '\n'
}using namespace fast_IO;
namespace TYX_YNXK{
	#define il inline
	#define bl bool
	#define ll long long
	#define ull unsigned long long
	#define vd void
	#define M 100005
	#define DEBUG cout<<"You are right,but you are wrong"<<'\n'
	#define END cout<<"You are right,but you are right now"<<'\n'
	ull Base[M]={1,1919891};
	#define base Base[1]
	il int idx(char c){
//		if(c>47&&c<58) return c-48;
//		if(c>64&&c<91) return c-55;
//		return c-61;
		return c-97;
	}
	int n,m;
	char ch[M];
	#define hash(h,l,r) ((r<l)?(0):(h[r]-h[l-1]*Base[r-(l)+1]))
//	#define hash(h,l,r) 0
	const int len=320;
	int cnt;
	struct node{
		int sz,pre,suf,rnk;
		int s[650];
		ull h[650],val;
		int& operator[](const int& pos){return s[pos];}
	}t[320];
	il vd pushup(int k){
		for(int i=1;i<=t[k].sz;i++) t[k].h[i]=t[k].h[i-1]*base+t[k][i];
		t[k].val=t[t[k].pre].val*Base[t[k].sz]+t[k].h[t[k].sz];
		t[k].rnk=t[t[k].pre].rnk+t[t[k].pre].sz;
	}
	il vd split(int a){
		int b=++cnt;
		int tmp=t[a].sz>>1;
		for(int i=tmp+1;i<=t[a].sz;i++) t[b][i-tmp]=t[a][i],t[a][i]=0;
		t[b].sz=t[a].sz-tmp;
		t[a].sz=tmp;
		t[b].suf=t[a].suf;
		t[b].pre=a;t[a].suf=b;
		pushup(a),pushup(b);
	}
	il vd init(){
		cnt=(n-1)/len+1;
		for(int i=1;i<=cnt;i++){
			if(i!=1) t[i].pre=i-1,t[i-1].suf=i;
			if(i==cnt) t[i].sz=n-(i-1)*len;
			else t[i].sz=len;
			for(int j=1;j<=t[i].sz;j++) t[i][j]=idx(ch[(i-1)*len+j-1]);
			pushup(i);
		}
	}
	il ull query(int ls,int rs,int l,int r){
		if(ls==rs) return hash(t[ls].h,l,r);
		return hash(t[ls].h,l,t[ls].sz)*Base[r+t[rs].rnk-t[t[ls].suf].rnk]+(t[t[rs].pre].val-t[ls].val*Base[t[rs].rnk-t[t[ls].suf].rnk])*Base[r]+hash(t[rs].h,1,r);
//		return 0;
	}
	il vd update(int x,int v){
		int pos=1;
		for(;pos;x-=t[pos].sz,pos=t[pos].suf) if(x<=t[pos].sz) break;
		t[pos][x]=v;
		pushup(pos);
		for(pos=t[pos].suf;pos;pos=t[pos].suf) t[pos].val=t[t[pos].pre].val*Base[t[pos].sz]+t[pos].h[t[pos].sz];
	}
	il vd insert(int x,int v){
		int pos=1;
		for(;pos;x-=t[pos].sz,pos=t[pos].suf) if(x<=t[pos].sz) break;
		for(int i=t[pos].sz;i>x;i--) t[pos][i+1]=t[pos][i];
		t[pos][x+1]=v,t[pos].sz++;
		pushup(pos);
		if(t[pos].sz>2*len) split(pos);
		for(pos=t[pos].suf;pos;pos=t[pos].suf) t[pos].val=t[t[pos].pre].val*Base[t[pos].sz]+t[pos].h[t[pos].sz],t[pos].rnk=t[t[pos].pre].rnk+t[t[pos].pre].sz;
	}
	signed main(){
		for(int i=2;i<=M-5;i++) Base[i]=Base[i-1]*base;
		cin>>ch;
		n=strlen(ch);
		init();
		cin>>m;
		while(m--){
			char opt[2];
			cin>>opt;
			switch(opt[0]){
				case 'Q':{
					int x,y;
					cin>>x>>y;
					if(x>y) swap(x,y);
					int xs=1,ys=1;
					int l=1,r=n-y+1,tmpx=x,tmpy=y,ls,rs,ans=0,mid;
					for(;xs;x-=t[xs].sz,xs=t[xs].suf) if(x<=t[xs].sz) break;
					for(;ys;y-=t[ys].sz,ys=t[ys].suf) if(y<=t[ys].sz) break;
//					DEBUG;
					ls=xs,rs=ys;
//					cout<<ls<<' '<<rs<<'\n';
					while(l<=r){
						mid=l+r>>1;
						int dx=tmpx+mid-1,dy=tmpy+mid-1;
//						cout<<t[ls].rnk<<'\n';
						dx-=t[ls].rnk,dy-=t[rs].rnk;
//						cout<<dx<<' '<<dy<<'\n';
						while(dx<=0) ls=t[ls].pre,dx+=t[ls].sz/*,cout<<ls<<' '<<dx<<'\n'*/;
						while(dx>t[ls].sz) dx-=t[ls].sz,ls=t[ls].suf;
						while(dy<=0) rs=t[rs].pre,dy+=t[rs].sz;
						while(dy>t[rs].sz) dy-=t[rs].sz,rs=t[rs].suf;
						if(query(xs,ls,x,dx)==query(ys,rs,y,dy)) ans=mid,l=mid+1;
						else r=mid-1;
					}
					cout<<ans<<'\n';
					break;
				}
				case 'R':{
					int x;char d[2];
					cin>>x>>d;
					update(x,idx(d[0]));
					break;
				}
				case 'I':{
					int x;char d[2];
					cin>>x>>d;
					n++;
					insert(x,idx(d[0]));
					break;
				}
			}
		}
		return 0;
	}
}
signed main(){
	TYX_YNXK::main();
	return 0;
}

感激不尽qwq

我都玄关了应该会有大佬来看吧

2024/1/19 12:15
加载中...