F - Isomorphic Strings

题目大意:给你一个长度为n 由小写字母组成的字符串,有m个询问, 每个询问给你两个区间, 问你xi,yi能不能形成映射关系。

思路:这个题意好难懂啊。。。  字符串哈希, 将26个字符分开来hash, 那么check就变成啦, 区间内对应的26个字符的hash值是否一致。

即如果 a -> b  那么区间1内a的hash值等于区间2内b的hash值。

 #include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define piii pair<int, pair<int,int>> using namespace std; const int N = 2e5 + ;
const int M = 1e4 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ; int n, m;
LL hs[][N], f[N], base = , seed = ;
char s[N]; vector<int> vec[];
LL getHash(int x, int l, int r) {
LL ans = hs[x][l];
if(r < n - ) ans -= hs[x][r + ] * f[r - l + ];
ans = (ans % mod + mod) % mod;
return ans;
} bool check(int l1, int r1, int l2, int r2) {
for(int j = ; j < ; j++) {
int p = lower_bound(vec[j].begin(), vec[j].end(), l1) - vec[j].begin();
if(p >= vec[j].size() || vec[j][p] > r1) continue;
if(getHash(j, l1, r1) != getHash(s[l2 + (vec[j][p] - l1)] - 'a', l2, r2))
return false;
}
return true;
}
int main() { f[] = ; for(int i = ; i < N; i++) f[i] = f[i - ] * base % mod;
scanf("%d%d", &n, &m);
scanf("%s", s);
n = strlen(s); for(int i = n - ; i >= ; i--) {
for(int j = ; j < ; j++) {
hs[j][i] = hs[j][i + ] * base % mod;
if(j == s[i] - 'a') {
hs[j][i] = (hs[j][i] + seed) % mod;
}
}
} for(int i = ; i < n; i++)
vec[s[i] - 'a'].push_back(i); while(m--) {
int x, y, len;
scanf("%d%d%d", &x, &y, &len);
int l1 = x - , l2 = y - , r1 = l1 + len - , r2 = l2 + len - ; if(check(l1, r1, l2, r2)) puts("YES");
else puts("NO");
}
return ;
} /*
*/

Educational Codeforces Round 44 (Rated for Div. 2) F - Isomorphic Strings的更多相关文章

  1. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  2. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  3. Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块

    Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 [Problem Description] ​ ...

  4. Educational Codeforces Round 44 (Rated for Div. 2)

    题目链接:https://codeforces.com/contest/985 ’A.Chess Placing 题意:给了一维的一个棋盘,共有n(n必为偶数)个格子.棋盘上是黑白相间的.现在棋盘上有 ...

  5. Educational Codeforces Round 50 (Rated for Div. 2) F - Relatively Prime Powers(数学+容斥)

    题目链接:http://codeforces.com/contest/1036/problem/F 题意: 题解:求在[2,n]中,x != a ^ b(b >= 2 即为gcd)的个数,那么实 ...

  6. Educational Codeforces Round 58 (Rated for Div. 2) F dp + 优化(新坑) + 离线处理

    https://codeforces.com/contest/1101/problem/F 题意 有n个城市,m辆卡车,每辆卡车有起点\(s_i\),终点\(f_i\),每公里油耗\(c_i\),可加 ...

  7. Educational Codeforces Round 42 (Rated for Div. 2)F - Simple Cycles Edges

    http://codeforces.com/contest/962/problem/F 求没有被两个及以上的简单环包含的边 解法:双联通求割顶,在bcc中看这是不是一个简单环,是的话把整个bcc的环加 ...

  8. Educational Codeforces Round 41 (Rated for Div. 2)F. k-substrings

    题意比较麻烦略 题解:枚举前缀的中点,二分最远能扩展的地方,lcp来check,然后线段树维护每个点最远被覆盖的地方,然后查询线段树即可 //#pragma GCC optimize(2) //#pr ...

  9. Educational Codeforces Round 33 (Rated for Div. 2) F. Subtree Minimum Query(主席树合并)

    题意 给定一棵 \(n\) 个点的带点权树,以 \(1\) 为根, \(m\) 次询问,每次询问给出两个值 \(p, k\) ,求以下值: \(p\) 的子树中距离 \(p \le k\) 的所有点权 ...

随机推荐

  1. linux下安装python和pip

    注意:不要轻易去卸载原有的python环境,因为有些软件是依赖他的 一:安装前,先将依赖环境一并安装,避免后面重复编译 [root@redhat2 bin]# yum install gcc g++ ...

  2. Training Neural Networks: Q&A with Ian Goodfellow, Google

    Training Neural Networks: Q&A with Ian Goodfellow, Google Neural networks require considerable t ...

  3. Spring Boot后台启动不打印nohup.out

    #!/bin/bashnohup java -jar websocket-server-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod --serve ...

  4. [转载]浅析为什么char类型的范围是 —128~+127

    http://blog.csdn.net/daiyutage/article/details/8575248 在C语言中, signed char 类型的范围为-128~127,每本教科书上也这么写, ...

  5. 【codeforces】940F题解

    CF Round #466的最后一题,颇有难度,正解是带修改莫队算法. [题意] 给定一个长度为\(n\)的数组\(a\),并且要求执行\(q\)个操作,有两种不同的操作: ①询问一个区间\([l,r ...

  6. 【HASPDOG】Communication error

    靠,防火墙没关,关了防火墙生成文件成功

  7. redis学习笔记之redis简介

    redis简介 Redis是一个开源的,高性能的,基于键值对的缓存与存储系统,通过设置各种键值数据类型来适应不同场景下的缓存与存储需求.同事redis的诸多高层级功能使其可以胜任消息队列,任务队列等不 ...

  8. [转载]如何在C++03中模拟C++11的右值引用std::move特性

    本文摘自: http://adamcavendish.is-programmer.com/posts/38190.htm 引言 众所周知,C++11 的新特性中有一个非常重要的特性,那就是 rvalu ...

  9. asp.net mvc 本地化 默认的错误提示

    System.ComponentModel.DataAnnotations 给我们提供了一些特性来直接对model的属性进行验证和约束, 同时也提供了 ErrorMessageResourceName ...

  10. ls和cd命令详解

    ls命令 命令功能: ​ 列出当前目录下或者指定目录下的所有文件和目录,ls是list的缩写. 命令语法: ls [选项][目录名 ] #注:[ ]中的内容为非必选项 命令选项: | 选项 | 含义 ...