【Vjudge】P1989Subpalindromes(线段树)
水题一道,用线段树维护哈希值,脑补一下加减乱搞搞……注意细节就过了
一定注意细节……
#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(线段树)的更多相关文章
- 【Vjudge】P558E A Simple Task(线段树暴力)
题目链接 这题……太暴力了吧…… 开二十六棵线段树维护l到r字符i出现的次数,然后修改的时候暴力修改,输出的时候暴力输出……就过了…… 然后我还没想到…… qwq #include<cstdio ...
- 线段树---Atlantis
题目网址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=110064#problem/A Description There are se ...
- 线段树——Ultra-QuickSort
题目网址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=109331#problem/A Description In this prob ...
- Mango DS Traning #49 ---线段树3 解题手记
Training address: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=38994#overview B.Xenia and B ...
- Mango DS Training #48 ---线段树2 解题手记
Training address: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=38966#overview A.Count Color ...
- HDU 4819 Mosaic 二维线段树
Mosaic Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- Codeforces Gym 100733J Summer Wars 线段树,区间更新,区间求最大值,离散化,区间求并
Summer WarsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.a ...
- HDU 4348 To the moon 可持久化线段树,有时间戳的区间更新,区间求和
To the moonTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.a ...
- [uva11992]Fast Matrix Operations(多延迟标记,二维线段树,区间更新)
题目链接:https://vjudge.net/problem/UVA-11992 题意:n*m的矩阵,每次对一个子矩阵操作,有三种操作:加x,设置为x,查询.查询返回子矩阵和.最小值.最大值 n很小 ...
随机推荐
- sessionStorage 详解,特点,使用技巧,场景
很早之前久知道sessionStorage ,也学习过,但没有实战使用过 .最近团队遇到一个问题<electronjs中打开新页面sessionStorage丢失>,让我有机会重新来认识一 ...
- 给广大码农分享福利:一个业界良心的github仓库,中文计算机资料
我今天查资料时无意发现的,https://github.com/CyC2018/CS-Notes 这个仓库包含了下列几个维度的计算机学习资料: 深受国内程序员喜爱,已经有超过3万多star了. 1. ...
- noip模拟赛#38
我打开了#39的problem...想了半个小时多发现我一道题都不会写...于是我打开了#38的problem T1:循环数字的定义为能够将该数划分为若干相同长度的段并且都相同. n=2e18. =& ...
- python_86_shutil模块
#高级的文件.文件夹.压缩包.处理模块 import shutil f1=open('sys模块.py','r',encoding='utf-8') f2=open('copy1.py','w',en ...
- loj6485 LJJ 学二项式定理
题目描述: loj 题解: 单位根反演. $[n|x]=\frac{1}{n} \sum _{i=0}^{n-1} (ω_n^x)^i$ 证明?显然啊,要么停在$(1,0)$要么转一圈. 所以说题目要 ...
- node 文件下载到本地 (支持中文文件名)
downloadfile:function(req,res,next){ var name= encodeURI(req.query.name); var path= req.query.url; v ...
- CentOS7安装配置VSFTP
#是否开启匿名用户,匿名都不安全,不要开 anonymous_enable=NO #允许本机账号登录FTP local_enable=YES #允许账号都有写操作 write_enable=YES # ...
- Voyager下的Settings方法
设置网站标题,logo,描述: 自定义setting字段,添加group为文章,key为title的字段: 添加成功: 前端页面写法: <img src="{{ Voyager::im ...
- mysql 编程
一.存储函数 相当于php或者js中有返回值的函数 --完成一定“计算”后返回单个的数据值 定义: create function 函数名(parameter p1 value_type, param ...
- 19.Yii2.0框架模型删除记录
目录 //删除记录 //http://yii.com/?r=home/del public function actionDel() { //查出要删除的记录行 // 方法一:(查一行,删一行) // ...