我写的代码好像自古以来就是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 ;
}

bzoj1014: [JSOI2008]火星人prefix splay+hash的更多相关文章

  1. bzoj1014: [JSOI2008]火星人prefix splay+hash+二分

    Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 ...

  2. 【BZOJ1014】[JSOI2008]火星人prefix Splay+hash

    [BZOJ1014][JSOI2008]火星人prefix Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个 ...

  3. BZOJ 1014: [JSOI2008]火星人prefix( splay + hash )

    用splay维护序列, 二分+hash来判断LCQ.. #include<bits/stdc++.h> using namespace std; typedef unsigned long ...

  4. BZOJ 1014 [JSOI2008]火星人prefix (Splay + Hash + 二分)

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 8112  Solved: 2569[Submit] ...

  5. 【bzoj1014】[JSOI2008]火星人prefix Splay+Hash+二分

    题目描述 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 8 9 10 ...

  6. BZOJ1014[JSOI2008]火星人prefix(splay维护hash)

    Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 ...

  7. BZOJ1014: [JSOI2008]火星人prefix(splay 二分 hash)

    题意 题目链接 Sol 一眼splay + 二分hash,不过区间splay怎么写来着呀 试着写了两个小时发现死活不对 看了一下yyb的代码发现自己根本就不会splay.... // luogu-ju ...

  8. [BZOJ1014] [JSOI2008] 火星人prefix (splay & 二分答案)

    Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 ...

  9. [bzoj1014](JSOI2008)火星人 prefix (Splay维护哈希)

    Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀. 比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 ...

随机推荐

  1. python的上下文管理器

    直接上代码: f = open('123.txt','w') try: f.write('hello world') except Exception: pass finally: f.close() ...

  2. 修复升级ndk到17.0.4754217编译so失败问题

    今天编译工程总过不去,查看失败原因,因为ndk的mips编译不过去. A problem occurred starting process ‘command ‘/Users/didi/Library ...

  3. BZOJ 1637 [Usaco2007 Mar]Balanced Lineup:前缀和 + 差分

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1637 题意: Farmer John 决定给他的奶牛们照一张合影,他让 N (1 ≤ N ...

  4. BZOJ 1634 [Usaco2007 Jan]Protecting the Flowers 护花:贪心【局部分析法】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1634 题意: 约翰留下他的N只奶牛上山采木.可是,当他回来的时候,他看到了一幕惨剧:牛们正 ...

  5. CC通信软件list

    bozokgh0stnanocoredarkcometponydarkcometadwindadzokaecomblacknixbluebananacorigaratdarkcometDRAThuig ...

  6. 阿里大于短信服务_异常_01_InvalidTimeStamp.Expired

    一.异常信息 dm.aliyuncs.com InvalidTimeStamp.Expired Specified time stamp or date value is expired. 二.异常原 ...

  7. c# json 排版

    public static string PraseToJson(string json) { try { JsonSerializer s = new JsonSerializer(); JsonR ...

  8. java中相对路径加载xml

    一.xml文件一般的存放位置有三个: 1.放在WEB-INF下: 2.xml文件放在/WEB-INF/classes目录下或classpath的jar包中: 3.放在与解析它的java类同一个包中,不 ...

  9. codeforces 705C C. Thor(模拟)

    题目链接: C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  10. hdu-5780 gcd(数学)

    题目链接: gcd Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/Others) Pro ...