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://codeforces.com/contest/985/problem/F
Description
You are given a string s of length n consisting of lowercase English letters.
For two given strings s and t, say S is the set of distinct characters of s and T is the set of distinct characters of t. The strings s and t are isomorphic if their lengths are equal and there is a one-to-one mapping (bijection) f between S and T for which f(si) = ti. Formally:
- f(si) = ti for any index i,
- for any character there is exactly one character that f(x) = y,
- for any character there is exactly one character that f(x) = y.
For example, the strings "aababc" and "bbcbcz" are isomorphic. Also the strings "aaaww" and "wwwaa" are isomorphic. The following pairs of strings are not isomorphic: "aab" and "bbb", "test" and "best".
You have to handle m queries characterized by three integers x, y, len (1 ≤ x, y ≤ n - len + 1). For each query check if two substrings s[x... x + len - 1] and s[y... y + len - 1] are isomorphic.
Sample Input
7 4
abacaba
1 1 1
1 4 2
2 1 3
2 4 3
Sample Output
YES
YES
NO
YES
题意
判断字符串是否同构
Judging two string have the same structure or not.
题解:
将字符串抽象成26个01串,如果对应字母的26个对应位置的子串相同,则字符串同构。
Create 26 01-string, if the substring which is locate at the same position, two string have the same structure.
代码
#include <bits/stdc++.h>
using namespace std;
int n, k;
string d;
bool a[50][200010];
vector<int> v[26];
long long hs[50][200010];
long long c[200010];
const long long inf = 0x3f3f3f3f;
const long long MOD = 1e9 + 7;
int main() {
cin >> n >> k >> d;
d = " " + d;
c[0] = 1;
for (int i = 1; i < d.size(); i++) {
a[d[i] - 'a'][i] = 1;
v[d[i] - 'a'].push_back(i);
c[i] = (c[i - 1] * inf) % MOD;
for (int j = 0; j < 26; j++)
hs[j][i] = (hs[j][i - 1] * inf + a[j][i]) % MOD;
}
for (int i = 1; i <= k; i++) {
int x, y, z;
cin >> x >> y >> z;
bool flag = 1;
for (int j = 0; j < 26; j++) {
int pos = lower_bound(v[j].begin(), v[j].end(), x )-v[j].begin();
if (pos<v[j].size())
pos = v[j][pos];
else
continue;
if (pos >= x + z) continue;
int dual = d[pos + y - x]-'a';
long long h1 = ((hs[j][x + z - 1] - hs[j][x - 1] * c[z]) % MOD + MOD) % MOD;
long long h2 = ((hs[dual][y + z - 1] - hs[dual][y - 1] * c[z]) % MOD + MOD) % MOD;
if (h1 != h2) {
flag = 0;
break;
}
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings的更多相关文章
- Educational Codeforces Round 44 (Rated for Div. 2) F - Isomorphic Strings
F - Isomorphic Strings 题目大意:给你一个长度为n 由小写字母组成的字符串,有m个询问, 每个询问给你两个区间, 问你xi,yi能不能形成映射关系. 思路:这个题意好难懂啊... ...
- 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 ...
- Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块
Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 [Problem Description] ...
- Educational Codeforces Round 44 (Rated for Div. 2)
题目链接:https://codeforces.com/contest/985 ’A.Chess Placing 题意:给了一维的一个棋盘,共有n(n必为偶数)个格子.棋盘上是黑白相间的.现在棋盘上有 ...
- 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)的个数,那么实 ...
- 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\),可加 ...
- Educational Codeforces Round 42 (Rated for Div. 2)F - Simple Cycles Edges
http://codeforces.com/contest/962/problem/F 求没有被两个及以上的简单环包含的边 解法:双联通求割顶,在bcc中看这是不是一个简单环,是的话把整个bcc的环加 ...
- Educational Codeforces Round 41 (Rated for Div. 2)F. k-substrings
题意比较麻烦略 题解:枚举前缀的中点,二分最远能扩展的地方,lcp来check,然后线段树维护每个点最远被覆盖的地方,然后查询线段树即可 //#pragma GCC optimize(2) //#pr ...
- Educational Codeforces Round 33 (Rated for Div. 2) F. Subtree Minimum Query(主席树合并)
题意 给定一棵 \(n\) 个点的带点权树,以 \(1\) 为根, \(m\) 次询问,每次询问给出两个值 \(p, k\) ,求以下值: \(p\) 的子树中距离 \(p \le k\) 的所有点权 ...
随机推荐
- 四百万条数据创建简单索引报错ora01652
经过几次度娘之后终于找到了解决方案,因为当时创建的indextest表是属于系统表空间,而系统表空间默认好像有大小限制,所以需要修改系统表空间的大小,至于修改表空间的语句可以随时度娘. 经过修改,创建 ...
- ARTS打卡计划第二周-Tips-mysql-binlog-connector-java的使用
最近发现一个挺不错的框架mysql-binlog-connector-java,可以实时监控binlog的变化. 首先检查mysql的binlog是否开启,在开启的情况下: 引入依赖 <depe ...
- 初学python笔记---列表
---恢复内容开始--- 1.列表的格式:用方括号([])来表示的,逗号来分隔元素,下标从0开始 2.根据下标来查看列表中元素,当索引为-1时,显示的是最后一个元素 print(a[0])-----1 ...
- Hbase--知识点总结3
Hbase知识点总结: hbase表中为什么列族的数量不能太多? 因为当一个列族数据溢写的时候,其他列族也会发生数据溢写,但是其他列族中数据的数量还没有达到溢写的阈值,就会导致产生的小文件数量增多. ...
- parallel Stream 学习
首先,我们需要了解下ForkJoinPool.ForkJoin框架是从jdk7中新特性,它同ThreadPoolExecutor一样,也实现了Executor和ExecutorService接口.它使 ...
- DNS 原理
一.DNS 是什么? DNS (Domain Name System 的缩写)的作用非常简单,就是根据域名查出IP地址.你可以把它想象成一本巨大的电话本. 举例来说,如果你要访问域名math.stac ...
- idea报错Target JRE version (1.8.0_191) does not match project JDK version (java version "1.7"), will use sources from JDK: 1.8
使用mac的idea 启动项目,总是报一个问题 我在idea中添加了多个jdk,项目启动的时候就只是配置了一个正确的,项目的配置完全正确.但是配置好tomcat后,启动就会报这个错误. 解决方案:需要 ...
- mycat使用之MySQL单库分表及均分数据
转载自 https://blog.csdn.net/smilefyx/article/details/72810531 1.首先在Mycat官网下载安装包,这里就以最新的1.6版本为例,下载地址为: ...
- python、java读数据
python从txt文档中读数据有个特别神奇的函数 可以把txt文档中的数据直接读取成python数组 java用Scanner类读数据比较方便
- docker安装nginx和php
参考文章:https://www.cnblogs.com/boundless-sky/p/7182410.html 1.下载镜像docker pull nginxdocker pull php:7.2 ...