【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很小 ...
随机推荐
- python零基础学习开篇
我是某工业大学的一名博士,研究方向是基于人脸的模式识别.很遗憾,毕业后没有继续从事图像处理中模式识别相关研究.多种原因进入了一家国企单位,从事交通方面工作.工作2年中一直迷茫,没有在工作岗位中找到自己 ...
- Problem N: 求二维数组中的鞍点【数组】
Problem N: 求二维数组中的鞍点[数组] Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2764 Solved: 1728[Submit][S ...
- C++内联函数、宏定义和普通函数的区别
C++内联函数.宏定义和普通函数的区别? 宏定义:在预处理阶段进行简单的文本替换,不会进行参数类型检查: 内联函数:在编译器的时候进行代码插入,编译器会在每次调用内联函数的地方直接将内联函数的内容展开 ...
- java基础—基础语法2
一.语句
- orcle定时备份
orcle定时备份 (1)写个.bat文件 例如: exp test/test@ORCL file=f:\back\test%date:~,%%date:~,%%date:~,%.dmp (2)开始, ...
- Bootstrap历练实例:大小Well
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- PAT 乙级 1045
题目 题目地址:PAT 乙级 1045 题解 本题的解法比较巧妙,刚开始的试着用暴力求解,果不其然时间超限…… 变换思路,既然对于每个元素来说满足的条件是前小后大,那么对数组排序,对应的位置相等的即为 ...
- 【思维题 并查集 图论】bzoj1576: [Usaco2009 Jan]安全路经Travel
有趣的思考题 Description Input * 第一行: 两个空格分开的数, N和M * 第2..M+1行: 三个空格分开的数a_i, b_i,和t_i Output * 第1..N-1行: 第 ...
- linux常用命令(配置查看,定时任务)
1.查看所有待挂载设备信息 fdisk -l # fdisk -l Disk /dev/sda: bytes heads, sectors/track, cylinders, total sector ...
- Yii2 AR模型搜索数据条数不对,AR模型默认去重
最近在做Yii2的项目时, 发现了一个yii2 自带的Ar模型会自动对搜索出来的字段去重. 默认去重字段: id, 其他字段暂没发现 1. 例如: public function fields { ...