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<\) 题目大意 : 给出一个长度为 \ ...
随机推荐
- css列表list、表格table
列表list,无序列表ul,有序列表ol 1.列表项样式list-style-type 无列表默认为dist实心圆,有序列表默认为decimal阿拉伯数字(前面不带0) 其他无序列表常用none无样式 ...
- Django XSS攻击
Django XSS攻击 XSS(cross-site scripting跨域脚本攻击)攻击是最常见的web攻击,其特点是“跨域”和“客户端执行”,XSS攻击分为三种: Reflected XSS(基 ...
- SSL/TLS代理(termination proxy)
A TLS termination proxy (or SSL termination proxy) is a proxy server that is used by an institution ...
- ldap集成confluence
confluence ldap配置跟jira ldap集成一样,请参考:https://www.cnblogs.com/imcati/p/9378668.html
- 缩点:Power Plant;
题目传送门:[UVALive 6437]Power Plant 题目大意:T组数据,给定一幅带权图(n, m), 然后给定k个点, 与图中存在有若干条边.每个点都要至少要和这k个点的一个点直接或间接相 ...
- 推荐 Net C# 逆向反编译四大工具利器
参考:https://blog.csdn.net/kongwei521/article/details/54927689/
- poj 3744 Scout (Another) YYF I - 概率与期望 - 动态规划 - 矩阵快速幂
(Another) YYF is a couragous scout. Now he is on a dangerous mission which is to penetrate into th ...
- 浅谈Windows用户帐户控制(User Account Control,UAC)
Microsoft一个事实:大多数用户都用一个Administrator(管理员)帐户来登录Windows.利用这个帐户,用户几乎没有任何限制地访问重要的系统资源,因为该帐户被授予很高的权限.一旦用户 ...
- 网络 --- 4 socketserver模块并发 连接合法性
一.socketserver模块 ②服务端 ③客户端 二.连接合法性 ①os.urandom(n) 一种bytes类型的随机生成n个字节字符串的方法 而且每次生成的值都不相同.再加上md5 ...
- C# 反射小结
废话不多说,直接上代码. 1.typeof(类名):它是一个运算符 eg_1:Type type = typeof(int) ; eg_2:public class Student { Type ty ...