我写的代码好像自古以来就是bzoj不友好型的

本地跑的比std快,但是交上去巧妙被卡

答案。。。应该是对的,拍了好久了

 #include <bits/stdc++.h>
#define MOD 998244353
#define mid (l+r>>1)
using namespace std;
int n,m,x,y;char ch;
long long mi[];
struct spla
{
int c[][],fa[],ch[],size[],ha[];
int rt,cnt;
void up(int now)
{
size[now]=size[c[now][]]+size[c[now][]]+;
ha[now]=(ha[c[now][]]+mi[size[c[now][]]]*ch[now]%MOD+mi[size[c[now][]]+]*ha[c[now][]]%MOD)%MOD;
}
void rot(int x,int &root)
{
int y=fa[x],k=c[y][]==x;
if(y!=root) c[fa[y]][c[fa[y]][]==y]=x;
else root=x;
fa[x]=fa[y];
fa[y]=x;
fa[c[x][!k]]=y;
c[y][k]=c[x][!k];
c[x][!k]=y;
up(y);up(x);
}
void splay(int x,int &root)
{
for(int y=fa[x];x!=root;rot(x,root),y=fa[x])
if(y!=root)
rot(((c[fa[y]][]==y)^(c[y][]==x))?x:y,root);
}
void add(int x,int y)
{
ch[++cnt]=y;size[cnt]=;ha[cnt]=y;
if(!rt)
{
rt=cnt;
return;
}
if(x==)
{
splay(fin(),rt);
c[rt][]=cnt;fa[cnt]=rt;
return;
}
splay(fin(x),rt);
if(x==n)
c[rt][]=cnt,fa[cnt]=rt;
else
splay(fin(x+),c[rt][]),c[c[rt][]][]=cnt,fa[cnt]=c[rt][];
}
/*
void add(int x,int y)
{
ch[++cnt]=y;size[cnt]=1;ha[cnt]=y;
if(!rt)
{
rt=cnt;
return;
}
int now=rt;
while(1)
{
if(x>size[c[now][0]])
if(c[now][1]) x-=size[c[now][0]]+1,now=c[now][1];
else
{
c[now][1]=cnt;fa[cnt]=now;
splay(cnt,rt);
return;
}
else
if(c[now][0]) now=c[now][0];
else
{
c[now][0]=cnt;fa[cnt]=now;
splay(cnt,rt);
return;
}
}
}*/
int fin(int x)
{
int now=rt;
while(x> || c[now][])
{
if(x==size[c[now][]]+)
break;
if(x>size[c[now][]])
x-=size[c[now][]]+,now=c[now][];
else
now=c[now][];
}
return now;
}
void change(int x,int y)
{
int now=fin(x);
splay(now,rt);
ch[now]=y;
up(now);
}
int hash(int x,int y)
{
if(x== && y==n) return ha[rt];
if(x==)
{
splay(fin(y+),rt);
return ha[c[rt][]];
}
if(y==n)
{
splay(fin(x-),rt);
return ha[c[rt][]];
}
splay(fin(x-),rt);
splay(fin(y+),c[rt][]);
return ha[c[c[rt][]][]];
}
} sp;
inline int read()
{
char ch=getchar();
for(;!isdigit(ch);ch=getchar());
int re=;
bool fl=;
if (ch=='-')
{
re=;
ch=getchar();
}
while (isdigit(ch))
{
re=re*+ch-'';
ch=getchar();
}
return fl?re:-re;
}
inline void write(int re)
{
if (re<)
{
putchar('-');
re=-re;
}
if (re>) write(re/);
putchar(re%+'');
}
void work(int x,int y)
{
if(x>y) swap(x,y);
int l=,r=n-y+;
while(l<r)
if(sp.hash(x,x+mid-)==sp.hash(y,y+mid-)) l=mid+;
else r=mid;
write(l-);puts("");
}
int main()
{
mi[]=;
for(int i=;i<=;i++)
mi[i]=mi[i-]*%MOD;
for(ch=getchar();isalpha(ch);ch=getchar())
sp.add(n,ch-'a'+),++n;
m=read();
for(int i=;i<=m;i++)
{
for(ch=getchar();!isalpha(ch);ch=getchar());
x=read();
if(ch=='Q') y=read();
else
{
char cas=ch;
for(ch=getchar();!isalpha(ch);ch=getchar());
y=ch-'a'+;
ch=cas;
}
if(i==)
int e=;
if(ch=='Q') work(x,y);
else
if(ch=='R')
sp.change(x,y);
else
sp.add(x,y),++n;
}
return ;
}

最新文章

  1. [翻译] ORMLite document -- How to Use Part (一)
  2. CGGeometry.h 文件详解
  3. Linux内核设计第六周 ——进程的描述和创建
  4. 深入理解js——一切都是对象
  5. LeetCode:Construct Binary Tree from Inorder and Postorder Traversal,Construct Binary Tree from Preorder and Inorder Traversal
  6. 通过注册表检测UAC是否处于关闭状态(不弹窗)
  7. http://www.cnblogs.com/amboyna/archive/2008/03/08/1096024.html
  8. Windows 7/8 自带定时关机命令
  9. Codeforces 56D Changing a String
  10. node.js实践第二天
  11. codility上的练习(3)
  12. QT中.pro文件的写法
  13. C语言语法tips(不断更新)
  14. Linux下编译memecaced
  15. scrapy选择器主要用法
  16. 分布式系统唯一ID的生成方案讨论
  17. JSESSIONID的简单说明
  18. 简单的OO ALV小示例
  19. git 取消文件跟踪
  20. Linux下编译安装redis

热门文章

  1. matlab之flipud()函数
  2. 写xml时候的一个坑
  3. 分享知识-快乐自己:搭建第一个 Hibernate (Demo)
  4. 1067 Bash 游戏v2
  5. 【Lintcode】017.Subsets
  6. 浏览器,tab页显示隐藏的事件监听--页面可见性
  7. Jasper:目录/资源
  8. 反射:newInstance()的使用方式
  9. chromium浏览器开发系列第五篇:Debugging with WinDBG
  10. 关于WPF的弹出窗口