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的更多相关文章

  1. 【题解】 Codeforces Edu44 F.Isomorphic Strings (字符串Hash)

    题面戳我 Solution 我们按照每个字母出现的位置进行\(hash\),比如我们记录\(a\)的位置:我们就可以把位置表示为\(0101000111\)这种形式,然后进行字符串\(hash\) 每 ...

  2. 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 ...

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

    F - Isomorphic Strings 题目大意:给你一个长度为n 由小写字母组成的字符串,有m个询问, 每个询问给你两个区间, 问你xi,yi能不能形成映射关系. 思路:这个题意好难懂啊... ...

  4. CodeForces985F -- Isomorphic Strings

    F. Isomorphic Strings time limit per test 3 seconds memory limit per test 256 megabytes input standa ...

  5. [LeetCode] Isomorphic Strings

    Isomorphic Strings Total Accepted: 30898 Total Submissions: 120944 Difficulty: Easy Given two string ...

  6. leetcode:Isomorphic Strings

    Isomorphic Strings Given two strings s and t, determine if they are isomorphic. Two strings are isom ...

  7. Codeforces 385B Bear and Strings

    题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. ...

  8. [leetcode]205. Isomorphic Strings 同构字符串

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  9. Codeforces 959 F. Mahmoud and Ehab and yet another xor task

    \(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...

随机推荐

  1. Maven 工程读取resource下的文件

    1:方式1: public static List<String> userList; static { userList = new LinkedList<String>() ...

  2. v-show v-if 的使用

    v-show:通过切换元素的display CSS属性实现显示隐藏: v-if:根据表达式的真假实现显示隐藏,如果隐藏,它绑定的元素都会销毁,显示的时候再重建: <div id="on ...

  3. Github网站加载不完全,响应超时,解决办法

    Github网站加载缓慢信息不全解决方法 Github是一个代码托管平台和开发者社区,开发者可以在Github上创建自己的开源项目并与其他开发者协作编码.毫不夸张地说,高效利用Github是一个优秀的 ...

  4. openstack cloud init set password

    设置代理和password #!/bin/bash cd /home/ubuntu wget otcloud-gateway.bj.intel.com/script.tar.gz ]; then cu ...

  5. openvas漏洞扫描

    openvas配置步骤 1.-因为老师给的kali中自带的openvas,所以我们可以直接执行命令:openvas-check-setup来查看下他的安装状态: 如下图所示:在步骤7中出现错误,其中图 ...

  6. Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password

    Centos7.5 执行ansible命令报错 问题: [root@m01 ~]# ansible servers -a "hostname" -i ./hosts -u root ...

  7. QML手动连接信号槽【Connections】

    1.使用Connections import QtQuick 2.6 import QtQuick.Window 2.2 import QtQuick.Controls 1.4 Window { vi ...

  8. uniGUI试用笔记(十一)

    最近研究了一下UniGUI的TuniDBGrid,记录一下免得忘记了. TuniDBGrid的重要属性包括: 1.列—TUniDBGridColumns和TUniDBGridColumn 每个列对象( ...

  9. uniGUI试用笔记(二)

    前几天做的demo今天启动后,浏览器打开页面后死活不显示窗体,找了半天原因才发现是360浏览器启动了兼容模式,改成极速模式后就正常了.有点晕.... 今天简单测试了TUniGUIServerModul ...

  10. FireMonkey 源码学习(5)

    (5)UpdateCharRec 该函数的源码分析如下: procedure TTextLayoutNG.UpdateCharRec(const ACanvas: TCanvas; NeedBitma ...