【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很小 ...
随机推荐
- 恢复为TrustedInstaller权限
每次我们要改动系统文件/文件夹时,都会被提示权限不够,而这个文件的所有者就是TrustInstaller.所以,就出现各种各样的教程,甚至傻瓜式的一键操作,让大家把自己设为文件的所有者,让自己得到最高 ...
- UVA12906 Maximum Score (组合)
对于每个元素,最理想的情况就是都在它的左边或者右边,那么sort一下就可以得到一个特解了,然后大的中间不能有小的元素,因为如果有的话,那么无论选小的还是选大的都不是最优.对小的元素来说,比它大的元素在 ...
- Servlet中的属性(attribute)和参数(parameter)的区别
1.引子 初学者对属性(attribute)和参数(parameter)容易搞混.没搞清他们的区别,项目中就可能出现一此莫名其妙的问题. 2.两者的区别 1) 属性(attribute) 属性是在后台 ...
- APT和它的超级牛力
当你在使用apt时,例如“apt -h”会提示“本APT具有超级牛” 先把牛放一放,先学习以下关于APT的知识. APT 高级打包工具(英语:Advanced Packaging Tools,缩写为A ...
- iBatis for net 框架使用
简介:ibatis 一词来源于“internet”和“abatis”的组合,是一个由Clinton Begin在2001年发起的开放源代码项目,到后面发展的版本叫MyBatis但都是指的同一个东西.最 ...
- WinForm中Timer倒计时
添加一个Timer控件: 在初始化代码中 public Form1() { InitializeComponent(); button_Read.Enabled = false; button_Sta ...
- 沙盒(SandBox)
iOS 应用沙盒机制就是指 iOS 应用程序只能在为该程序创建的文件系统中读取文件,不可以去其它地方访问,此区域被成为沙盒,所以所有的非代码文件都要保存在此,例如图像,图标,声音,映像,属性列表,文本 ...
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- TB平台搭建之一
最近在搭建公司的testbench,主要有一下总结: 1.TB主要有两部分:部分一,软件部分主要用C写的,她的作用是写硬件的驱动(其实就是让核的外围设备可以正常工作或工作到特定的环境上)甚至有可能写整 ...
- 一个炫酷的flash网站模板
这是一个炫酷的flash欧美网站模板,它包括首页,公司简介,留言等五个页面,界面转换非常的炫酷!他还有时间.全屏.背景音乐开关的功能!有兴趣的朋友可以看看!贴几张网站图片给大家看看! 下载后直接找到s ...