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\) 的所有点权 ...
随机推荐
- Java框架spring Boot学习笔记(七):@Configuration,@bean注解
@Configuration作用在类上,相当于一个xml文件 @bean作用于方法上,相当于xml配置中的<bean>标签 一个例子: 新建一个Springboot工程 新建一个User类 ...
- AHB协议整理 AMBA
本文对AHB协议作了简单整理,整理自两篇文章: AHB总线协议 AHB重点难点总结 1. 简介 AHB总线规范是AMBA总线规范的一部分,AMBA总线规范是ARM公司提出的总线规范,被大多数SoC设计 ...
- Ubuntu16.04 藍牙連上,但是聲音裏面找不到設備
解決辦法: 1. sudo apt-get install blueman bluez* 2. sudo vim /etc/pulse/default.pa 注釋掉下面的代碼: #.ifexists ...
- android一个app打开另一个app的指定页面
一个app打开另一个app的指定页面方法 有以下几种 1.通过包名.类名 2.通过intent的 action 3.通过Url 方案1. ComponentName componentName = n ...
- Gulp入门及简单使用
前言 什么是gulp?gulp有什么用?为什么用gulp? gulp是前端开发的一种构建工具. 构建工具可以帮助我们工程化地开发项目,比如搭建本地服务器.编译CSS预处理器.保存文件后自动刷新浏览器而 ...
- 获取txt md5值上传文件完整性校验
网络上传文件到服务器 做md5 校对.判断文件是否破坏 首先求txt文件的md5值 ,1万条数据 求出的值 文件MD5:e5467b6a8e3c26af8c5af0bda3739280 服务器处理程序 ...
- centos7 安装mysql5.7.20(yum方式)
windows下安装mysql请访问:windows下mysql5.7.20安装(zip包方式) 一.安装过程 1.安装wget yum install wget 2.查找yum源名称 在mysql官 ...
- CNA, FCoE, TOE, RDMA, iWARP, iSCSI等概念及 Chelsio T5 产品介绍 转载
CNA, FCoE, TOE, RDMA, iWARP, iSCSI等概念及 Chelsio T5 产品介绍 2016年09月01日 13:56:30 疯子19911109 阅读数:4823 标签: ...
- 《Oracle查询优化改写技巧与案例》学习笔记-------使用数字篇
一个系列的读书笔记,读的书是有教无类和落落两位老师编写的<Oracle查询优化改写技巧与案例>. 用这个系列的读书笔记来督促自己学习Oracle,同时,对于其中一些内容,希望大家看到以后, ...
- laraval migration 新增字段或者修改字段的方法
1.进入项目根目录执行artisan命令生成migration文件,可以指定--table和--path参数,会在对应目录下生成migration文件. php artisan make:migrat ...