Educational Codeforces Round 44 (Rated for Div. 2) F - Isomorphic Strings
题目大意:给你一个长度为n 由小写字母组成的字符串,有m个询问, 每个询问给你两个区间, 问你xi,yi能不能形成映射关系。
思路:这个题意好难懂啊。。。 字符串哈希, 将26个字符分开来hash, 那么check就变成啦, 区间内对应的26个字符的hash值是否一致。
即如果 a -> b 那么区间1内a的hash值等于区间2内b的hash值。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define piii pair<int, pair<int,int>> using namespace std; const int N = 2e5 + ;
const int M = 1e4 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ; int n, m;
LL hs[][N], f[N], base = , seed = ;
char s[N]; vector<int> vec[];
LL getHash(int x, int l, int r) {
LL ans = hs[x][l];
if(r < n - ) ans -= hs[x][r + ] * f[r - l + ];
ans = (ans % mod + mod) % mod;
return ans;
} bool check(int l1, int r1, int l2, int r2) {
for(int j = ; j < ; j++) {
int p = lower_bound(vec[j].begin(), vec[j].end(), l1) - vec[j].begin();
if(p >= vec[j].size() || vec[j][p] > r1) continue;
if(getHash(j, l1, r1) != getHash(s[l2 + (vec[j][p] - l1)] - 'a', l2, r2))
return false;
}
return true;
}
int main() { f[] = ; for(int i = ; i < N; i++) f[i] = f[i - ] * base % mod;
scanf("%d%d", &n, &m);
scanf("%s", s);
n = strlen(s); for(int i = n - ; i >= ; i--) {
for(int j = ; j < ; j++) {
hs[j][i] = hs[j][i + ] * base % mod;
if(j == s[i] - 'a') {
hs[j][i] = (hs[j][i] + seed) % mod;
}
}
} for(int i = ; i < n; i++)
vec[s[i] - 'a'].push_back(i); while(m--) {
int x, y, len;
scanf("%d%d%d", &x, &y, &len);
int l1 = x - , l2 = y - , r1 = l1 + len - , r2 = l2 + len - ; if(check(l1, r1, l2, r2)) puts("YES");
else puts("NO");
}
return ;
} /*
*/
Educational Codeforces Round 44 (Rated for Div. 2) F - Isomorphic Strings的更多相关文章
- 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 ...
- 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\) 的所有点权 ...
随机推荐
- VS批处理命令使用
在项目开始生成或者生成完成后想做一些操作,比如去编译非解决方案下的的项目,完成编译后复制文件到某个文件夹之类的纠结需求. 1. 基本使用 预先生成事件命令行,可以在项目编译的过程中运行 后期生成事件命 ...
- KVM基本实现原理
KVM 虚拟化技术概述 http://blog.csdn.net/yearn520/article/details/6461047 KVM 虚拟化技术在 AMD 平台上的实现 1.http://www ...
- 解决错误:Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
在使用yum install的时候,偶尔会碰见这样的错误:Couldn’t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 这是因为在你的 /etc/yum ...
- windows安装filebeat服务报错
cmd进入filebeat目录下 用以下命令执行: PowerShell.exe -ExecutionPolicy UnRestricted -File .\install-service-fil ...
- 【c#】腾讯人脸识别api签名
using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using Syst ...
- VsCode搭建Java开发环境(Spring Boot项目创建、运行、调试)
源码地址:https://github.com/YANGKANG01/Spring-Boot-Demo 安装扩展 安装如下两个主要扩展即可,这两个扩展已关联java项目开发主要使用的maven.spr ...
- @Controller,@Service,@Repository,@Component详解
@Controller 用来表示一个web控制层bean,如SpringMvc中的控制器. @Service 用来表示一个业务层bean. @Repository 用来表示一个持久层bean,即数据访 ...
- 【整理】HTML5游戏开发学习笔记(1)- 骰子游戏
<HTML5游戏开发>,该书出版于2011年,似乎有些老,可对于我这样没有开发过游戏的人来说,却比较有吸引力,选择自己感兴趣的方向来学习html5,css3,相信会事半功倍.不过值得注意的 ...
- [php]mysqli操作流程
<?php class SqlTools{ private $con; private $trans; public function __construct($host, $user, $ps ...
- 【leetcode 简单】 第五十六题 快乐数
编写一个算法来判断一个数是不是“快乐数”. 一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 1,也可能是无限循环但始终变不到 1.如 ...