题目链接

  水题一道,用线段树维护哈希值,脑补一下加减乱搞搞……注意细节就过了

  一定注意细节……

#include<cstdio>
#include<cstdlib>
#include<cctype>
#include<algorithm>
#include<cstring>
#define maxn 100050
#define base 163
#define left (rt<<1)
#define right (rt<<1|1)
#define mid ((l+r)>>1)
#define lson l,mid,left
#define rson mid+1,r,right
using namespace std; unsigned long long d[maxn*];
unsigned long long w[maxn*];
unsigned long long bs[maxn];
char q[maxn]; inline int count(char c){ return c-'a'+; } inline void pushup(int rt,int m){
d[rt]=d[left]*bs[m>>]+d[right];
w[rt]=w[right]*bs[m-(m>>)]+w[left];
} void build(int l,int r,int rt){
if(l==r){
d[rt]=w[rt]=count(q[l]);
return;
}
build(lson);
build(rson);
pushup(rt,r-l+);
} unsigned long long queryfro(int from,int to,int l,int r,int rt){
if(from<=l&&to>=r) return d[rt];
unsigned long long ans=;
int len=;
if(to>mid){
len=min(to,r)-mid;
ans=queryfro(from,to,rson);
}
if(from<=mid) ans+=queryfro(from,to,lson)*bs[len];
return ans;
} unsigned long long querysub(int from,int to,int l,int r,int rt){
if(from<=l&&to>=r) return w[rt];
unsigned long long ans=;
int len=;
if(from<=mid){
len=mid-max(from,l)+;
ans=querysub(from,to,lson);
}
if(to>mid) ans+=querysub(from,to,rson)*bs[len];
return ans;
} void update(int o,char c,int l,int r,int rt){
if(l==r){
d[rt]=w[rt]=count(c);
return;
}
if(o<=mid) update(o,c,lson);
else update(o,c,rson);
pushup(rt,r-l+);
} int main(){
scanf("%s",q+);
int n=strlen(q+),m;
scanf("%d",&m);
bs[]=; for(int i=;i<=n;++i) bs[i]=bs[i-]*base;
build(,n,);
for(int i=;i<=m;++i){
char c[]; int x,y;char o[];
scanf("%s%d",c,&x);
if(c[]=='p'){
scanf("%d",&y);
if(queryfro(x,y,,n,)==querysub(x,y,,n,)) printf("Yes\n");
else printf("No\n");
}
else{
scanf("%s",o);
update(x,o[],,n,);
}
}
return ;
}
/*
abcda
5
palindrome? 1 5
palindrome? 1 1
change 4 b
palindrome? 1 5
palindrome? 2 4
*/

【Vjudge】P1989Subpalindromes(线段树)的更多相关文章

  1. 【Vjudge】P558E A Simple Task(线段树暴力)

    题目链接 这题……太暴力了吧…… 开二十六棵线段树维护l到r字符i出现的次数,然后修改的时候暴力修改,输出的时候暴力输出……就过了…… 然后我还没想到…… qwq #include<cstdio ...

  2. 线段树---Atlantis

    题目网址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=110064#problem/A Description There are se ...

  3. 线段树——Ultra-QuickSort

    题目网址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=109331#problem/A Description In this prob ...

  4. Mango DS Traning #49 ---线段树3 解题手记

    Training address: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=38994#overview B.Xenia and B ...

  5. Mango DS Training #48 ---线段树2 解题手记

    Training address: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=38966#overview A.Count Color ...

  6. HDU 4819 Mosaic 二维线段树

    Mosaic Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  7. Codeforces Gym 100733J Summer Wars 线段树,区间更新,区间求最大值,离散化,区间求并

    Summer WarsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.a ...

  8. HDU 4348 To the moon 可持久化线段树,有时间戳的区间更新,区间求和

    To the moonTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.a ...

  9. [uva11992]Fast Matrix Operations(多延迟标记,二维线段树,区间更新)

    题目链接:https://vjudge.net/problem/UVA-11992 题意:n*m的矩阵,每次对一个子矩阵操作,有三种操作:加x,设置为x,查询.查询返回子矩阵和.最小值.最大值 n很小 ...

随机推荐

  1. Vue中npm run build报“Error in parsing SVG: Unquoted attribute value”

    自己做的一个Vue项目,在打包时老是报这个错误 # Error in parsing SVG: Unquoted attribute value 查了查网上说的,都说报错原因是压缩和抽离CSS的插件中 ...

  2. 解决cocos2dx 3.x 导入cocostudio的ui界面出现错位问题

    笔者今天发现导入cocostudio的ui界面时,会有部分控件出现错位的现象,后来我看了一下源码,发现是部分控件是没有继承 Layout类,导致不能设置控件位置造成,原因可以看看cocos2dx 源码 ...

  3. Docker DockerFile文件指令 & 构建

    1.dockerfile指令格式 # Comment注释 INSTRUCTION argument指令名 + 参数 2.普通指令 1. FROM 已存在的镜像,基础镜像,第一条非注释指令 FROM & ...

  4. Centos7系统下安装Docker

    1.确定你的Linux系统是Centos7 命令:cat /etc/redhat-release 2.yum安装gcc相关 1.配置好Centos7能上外网. 2.yum -y install gcc ...

  5. Python爬虫系列-PyQuery详解

    强大又灵活的网页解析库.如果你觉得正则写起来太麻烦,如果你觉得BeautifulSoup语法太难记,如果你熟悉jQuery的语法,那么PyQuery就是你的最佳选择. 安装 pip3 install ...

  6. destoon模块自定义字段的添加并让其支持搜索的方法

    今天看了看模块设置里的自定义字段功能的用法,试着加了个新字段glry,设置了值,然后去数据库moduleid的article表看,字段成功加上了. 于是去template下article文件夹的lis ...

  7. 第6章 AOP与全局异常处理6.5-6.11 慕课网微信小程序开发学习笔记

    https://coding.imooc.com/learn/list/97.html 目录: 第6章 AOP与全局异常处理6-1 正确理解异常处理流程 13:236-2 固有的处理异常的思维模式与流 ...

  8. Pytorch学习(一)—— 自动求导机制

    现在对 CNN 有了一定的了解,同时在 GitHub 上找了几个 examples 来学习,对网络的搭建有了笼统地认识,但是发现有好多基础 pytorch 的知识需要补习,所以慢慢从官网 API进行学 ...

  9. 中移物联网onenet入门学习笔记1:资料获取

    onenet学习资料.视频.例程汇总:https://open.iot.10086.cn/bbs/thread-977-1-1.html onenet开发文档:https://open.iot.100 ...

  10. UVALive - 3942 Remember the Word (Trie + DP)

    题意: 给定一篇长度为L的小写字母文章, 然后给定n个字母, 问有多少种方法用这些字母组成文章. 思路: 用dp[i]来表达[i , L]的方法数, 那么dp[i] 就可以从dp[len(x) + i ...