bzoj2628: JZPSTR
Description
0. 在位置x_i处插入一个字符串y_i
1. 删除位置[x_i, y_i)的字符串
2. 查询位置[x_i, y_i)的字符串包含多少次给定的子串z_i
Input
下面T行,每行第一个数p_i,表示这个操作的类型:
若p_i=0,则接下来有一个整数x_i和一个字符串y_i,表示进行插入操作;
若p_i=1,则接下来有两个整数x_i和y_i,表示进行删除操作;
若p_i=2,则接下来有两个整数x_i和y_i,以及一个字符串z_i,表示进行询问。
字符串的下标从0开始(即第一个字符的下标为0)。
初始时字符串为空。
对于插入操作,插入后字符串y_i的首字符的下标应为x_i;
对于删除操作,删除的区间[x_i, y_i)为左闭右开区间;
对于查询操作,询问的区间[x_i, y_i)为左闭右开区间。
所有插入的和查询的字符串均不为空,且只包含0~9的字符。
所有询问的区间和删除的区间均不为空。
保证输入数据合法。
对于"左闭右开区间"不理解的可以去看样例解释。
Output
暴力的复杂度约为1010,于是可以压位维护每个字符的所有出现位置,插入删除直接暴力,查询则可以通过移位和按位与实现。
由于bitset封装的太好不便于高效区间操作所以还是手写一个。。
#include<cstdio>
#include<cstring>
typedef unsigned long long u64;
char buf[],*ptr=buf-;
int n,o,x,y;
char s[];
int c1[];
const u64 N=/;
u64 b[N];
struct bitvec{
u64 a[N];
int len;
void set(int x){a[x>>]|=1llu<<x;}
void reset(int x){a[x>>]&=~(1llu<<x);}
void set(int x,bool a){if(a)set(x);else reset(x);}
bool test(int x){return a[x>>]>>x&;}
void ins(int x,int y){
len+=y;
register int p=len+>>;
int r=x+y+>>;
int d1=y>>,d2=y&,d3=-d2;
if(d2)for(;p>=r;--p)a[p]=a[p-d1-]>>d3|a[p-d1]<<d2;
else for(;p>=r;--p)a[p]=a[p-d1];
p=p+<<;
while(p>x+y)--p,set(p,test(p-y));
}
void del(register int x,int y){
len-=y;
while(x<len&&(x&))set(x,test(x+y)),++x;
if(x==len)return;
x>>=;
int r=len+>>;
int d1=y>>,d2=y&,d3=-d2;
if(d2)for(;x<=r;++x)a[x]=a[x+d1]>>d2|a[x+d1+]<<d3;
else for(;x<=r;++x)a[x]=a[x+d1];
}
void cut(int x,int y){
int r=y+>>,d1=x>>,d2=x&,d3=-d2;
if(d2)for(register int i=;i<r;++i)b[i]&=a[d1+i]>>d2|a[d1+i+]<<d3;
else for(register int i=;i<r;++i)b[i]&=a[d1+i];
}
}v[];
int _(){
int x=,c=*++ptr;
while(c<)c=*++ptr;
while(c>)x=x*+c-,c=*++ptr;
return x;
}
void _(char*s){
int c=*++ptr;
while(c<)c=*++ptr;
while(c>)*s++ =c,c=*++ptr;
*s=;
}
int main(){
for(int i=;i<;++i)c1[i]=c1[i>>]+(i&);
fread(buf,,sizeof(buf),stdin);
n=_();
while(n--){
o=_();x=_();
if(o==){
_(s);
y=strlen(s);
for(int i=;i<;++i){
v[i].ins(x,y);
for(int j=;j<y;++j)v[i].set(x+j,s[j]==''+i);
}
}else if(o==){
y=_()-x;
for(int i=;i<;++i)v[i].del(x,y);
}else{
y=_()-x;_(s);
int l=strlen(s),ans=;
if(l<=y){
int d=y-l+;
memset(b,-,d+>>);
for(int i=;i<l;++i)v[s[i]-''].cut(x+i,d);
while(d&)--d,ans+=b[d>>]>>d&;
d>>=;
for(int i=;i<d;++i)ans+=c1[b[i]&]+c1[b[i]>>&]+c1[b[i]>>&]+c1[b[i]>>];
}
printf("%d\n",ans);
}
}
return ;
}
bzoj2628: JZPSTR的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
随机推荐
- Python -- OOP高级 -- 元类
type()函数既可以返回一个对象的类型,又可以创建出新的类型 def fn(self, name="world"): print("Hello, %s!" % ...
- Hibernate锁机制
业务逻辑的实现过程中,往往需要保证数据访问的排他性.因此,我们就需要通过一些机制来保证这些数据在某个操作过程中不会被外界修改,这样的机制,在这里,也就是所谓的“锁”,即给我们选定的目标数据上锁,使其无 ...
- 凹凸曼的修改zencart 程序(经典!)
==================================================================================================== ...
- Chapter 1 First Sight——11
I didn't relate well to people my age. 我没有向人们叙述清楚我的年龄 Maybe the truth was that I didn't relate well ...
- AngularJs: Reload page
<a ng-click="reloadRoute()" class="navbar-brand" title="home" data- ...
- Textbox服务器控件
<body> <form id="form1" runat="server"> <div> 姓名:<asp:TextB ...
- 服务器修改 ssh 22端口
我们首先修改配置文件,让ssh 通知支持2个端口访问 ,22 和 23456 端口. Port 22 Port 23456 为什么要这样: 万一我用 23456端口替换了22端口,但是 23456正好 ...
- ANSI X9.8标准 PIN xor PAN获取PIN BlOCK
ANSI X9.8标准 PIN xor PAN获取PIN BlOCK 之前看到几篇介绍,把ANSI说成16个字节,真心扯淡,各种误人子弟,真正的ANSI算法其实是8个字节,具体格式如下: (1) AN ...
- java调用dll-JNA
介绍 给大家介绍一个最新的访问本机代码的 Java 框架 —JNA . JNA(Java Native Access) 框架是一个开源的 Java 框架,是 SUN 公司主导开发的,建立在经典的 JN ...
- 神经网络joone_engin模式识别示范,eclipse
链接: http://pan.baidu.com/s/1kVRducv 密码: junw