Codeforces 985 F - Isomorphic Strings
思路:
字符串hash
对于每一个字母单独hash
对于一段区间,求出每个字母的hash值,然后排序,如果能匹配上,就说明在这段区间存在字母间的一一映射
代码:
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 2e5 + ;
const int MOD = 1e9 + ;
const int base = ;
char s[N];
LL Hash[N][], p[N], t[], tt[];
LL get_H(int l, int r, int i) {
return ((Hash[r][i] - Hash[l-][i]*p[r-l+])%MOD + MOD)%MOD;
}
bool check(int x, int y, int len) {
for (int i = ; i < ; i++) {
t[i] = get_H(x, x+len-, i);
tt[i] = get_H(y, y+len-, i);
}
sort(t, t+);
sort(tt, tt+);
for (int i = ; i < ; i++) if(t[i] != tt[i]) return false;
return true;
}
int main() {
int n, m, x, y, len;
scanf("%d%d", &n, &m);
scanf("%s", s+);
p[] = ;
for (int i = ; i <= n; i++) p[i] = (p[i-] * base) % MOD;
for (int i = ; i <= n; i++) {
for (int j = ; j < ; j++) {
Hash[i][j] = (Hash[i-][j] * base + (s[i] == 'a'+j))%MOD;
}
}
while(m--) {
scanf("%d%d%d", &x, &y, &len);
if(check(x, y, len)) puts("YES");
else puts("NO");
}
return ;
}
Codeforces 985 F - Isomorphic Strings的更多相关文章
- 【题解】 Codeforces Edu44 F.Isomorphic Strings (字符串Hash)
题面戳我 Solution 我们按照每个字母出现的位置进行\(hash\),比如我们记录\(a\)的位置:我们就可以把位置表示为\(0101000111\)这种形式,然后进行字符串\(hash\) 每 ...
- 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 ...
- Educational Codeforces Round 44 (Rated for Div. 2) F - Isomorphic Strings
F - Isomorphic Strings 题目大意:给你一个长度为n 由小写字母组成的字符串,有m个询问, 每个询问给你两个区间, 问你xi,yi能不能形成映射关系. 思路:这个题意好难懂啊... ...
- CodeForces985F -- Isomorphic Strings
F. Isomorphic Strings time limit per test 3 seconds memory limit per test 256 megabytes input standa ...
- [LeetCode] Isomorphic Strings
Isomorphic Strings Total Accepted: 30898 Total Submissions: 120944 Difficulty: Easy Given two string ...
- leetcode:Isomorphic Strings
Isomorphic Strings Given two strings s and t, determine if they are isomorphic. Two strings are isom ...
- Codeforces 385B Bear and Strings
题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. ...
- [leetcode]205. Isomorphic Strings 同构字符串
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- Codeforces 959 F. Mahmoud and Ehab and yet another xor task
\(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...
随机推荐
- Vue小案例 之 商品管理------学习过滤器 使用过滤器处理日期的格式
代码学习过滤器 过滤器介绍:过滤模型数据,在数据显示前做预处理操作: 内置过滤器:在1.x中,Vue提供了内置过滤器,但是在2.x中已经完全废除: 解决办法: (1)使用第三方库来替代1.x中的内置过 ...
- P2765 魔术球问题
P2765 魔术球问题 贪心模拟就可以过.........好像和dinic没啥关系 找找规律发现可以贪心放.n又灰常小. 设答案=m 你可以$O(mn)$直接模拟过去 闲的慌得话可以像我用个$se ...
- Spring Boot(六):如何使用mybatis
Spring Boot(六):如何使用mybatis orm框架的本质是简化编程中操作数据库的编码,发展到现在基本上就剩两家了,一个是宣称可以不用写一句SQL的hibernate,一个是可以灵活调试动 ...
- LVS群集配置
第一步:网络环境配置内网网段:10.0.0.0/24DR:10.0.0.254rs1:10.0.0.1rs2:10.0.0.2nfs:10.0.0.3 第二步:nfs和web服务搭建 nfs服务器:安 ...
- windows安装 php-redis redis 扩展
1.查看phpinfo(),确定要下载的扩展版本,扩展的下载地址在:https://pecl.php.net/package/redis 上图对应是是以下版本 2.把下载包里的文件放到php的ext文 ...
- H5浏览器播放RTMP直播流实现切换
切换直播源的参考:http://blog.csdn.net/u012737182/article/details/73920830
- Java多线程编程作业总结
一.多线程知识总结 1.线程同步 有关创建线程的知识就不过多的叙述了.就从主要的开始讲吧,讲一下线程的同步.与操作系统中的进程同步一样,线程同样面临着资源共享的问题,怎样处理线程的资源共享是运用多线程 ...
- Arrays的排序算法sort及方法使用
Java工具包中的Arrays工具类里面有数组的快速排序算法. 源码如下: /** * Sorts the specified range of the array using the given * ...
- Eclipse中在xml文件中,ctrl+左键的快捷键,点击class定位,不生效
修改方式: 第一种方式:Window -> Preferences -> General -> Editors -> File Associations ...
- CentOS6.8下安装mysql
转自https://blog.csdn.net/jeffleo/article/details/53559712?utm_source=itdadao&utm_medium=referral ...