题目链接

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

  一定注意细节……

#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. Firefox火狐广告过滤插件Adblock Plus过滤规则包[中文维护小组]

    如果你经常使用Firefox火狐浏览器那么一定知道Adblock Plus这款广告过滤插件,功能非常强大,但是Adblock Plus广告过滤插件自带的过滤规则并不多,而且也不太适合我们中国的网站,在 ...

  2. Codeforces Round #321 (Div. 2) D Kefa and Dishes(dp)

    用spfa,和dp是一样的.转移只和最后一个吃的dish和吃了哪些有关. 把松弛改成变长.因为是DAG,所以一定没环.操作最多有84934656,514ms跑过,实际远远没这么多. 脑补过一下费用流, ...

  3. MySQL基础教程——mysql脚本编写

    SQL,结构化查询语言,既是对数据库进行操作的语言,也是数据库脚本文件的扩展名. 要求:新建一个名为 library 的数据库,包含 book.reader 两张表,根据自己的理解安排表的内容并插入数 ...

  4. 2018.5.11 Java利用反射实现对象克隆

    package com.lanqiao.demo; /** * 创建人 * @author qichunlin * */ public class Person { private int id; p ...

  5. 爬虫1_python2

    # -*- coding: UTF-8 -*- # python2爬虫 import urllib f = urllib.urlopen("http://www.itcast.cn/&quo ...

  6. Python-DDT实现接口自动化

    Get请求参数化例子 import unittest import requests import ddt @ddt.ddt class MyTestCase(unittest.TestCase): ...

  7. oracle系統表、數據字典介紹與日常問題診斷

    oracle系統表.數據字典介紹與日常問題診斷 數據字典是由唯讀的table和view組成的,產生於$oracle_home\rdbms\admin\catalog.sql.裡面儲存Oracle資料庫 ...

  8. 53. Maximum Subarray@python

    Given an integer array nums, find the contiguous subarray (containing at least one number) which has ...

  9. poj1654 Area

    题目描述: vjudge POJ 题解: 本以为是水题结果是神题 计算几何求多边形面积. 考虑到结果一定是整数或者整数/2,我们应该用long long 来存…… 用double会死…… 还有日常只能 ...

  10. [LUOGU] P4251 [SCOI2015]小凸玩矩阵

    行列看成点,格子看成边,二分一个边权,删去大于它的边,新图上的最大流>k则答案可以更优,小于k则调整左边界. #include<algorithm> #include<iost ...