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\) 的所有点权 ...
随机推荐
- Java并发编程原理与实战三十二:ForkJoin框架详解
1.Fork/Join框架有什么用呢? ------->Fork使用来切分任务,Join是用来汇总结果.举个简单的栗子:任务是1+2+3+...+100这个任务(当然这个任务的结果有好的算法去做 ...
- soj1047.Super Snooker(转换思路+二路求和)
Description On one of my many interplanetary travels I landed on a beautiful little planet called Cr ...
- codeforces997C Sky full of stars
传送门:http://codeforces.com/problemset/problem/997/C [题解] 注意在把$i=0$或$j=0$分开考虑的时候,3上面的指数应该是$n(n-j)+j$ 至 ...
- oracle关键字作为字段名使用方法
有时我们在定义字段名及别名时所用名与oracle关键字同名,这时该如何处理呢? 其实很简单,只要在此关键字加上"",如"group" SQL> DROP ...
- Centos7安装 mysql5.6.29 shell脚本
有很多可以借鉴的地方,故转载: 创建脚本mysql.sh,直接运行sh mysql.sh !/bin/bash if [ -d /software ] ;then cd /software else ...
- 最短路径—Floyd算法
Floyd算法 所有顶点对之间的最短路径问题是:对于给定的有向网络G=(V,E),要对G中任意两个顶点v,w(v不等于w),找出v到w的最短路径.当然我们可以n次执行DIJKSTRA算法,用FLOYD ...
- aarch64_o2
opensips-event_rabbitmq-2.2.3-1.fc26.aarch64.rpm 2017-03-10 01:22 42K fedora Mirroring Project opens ...
- aarch64_l1
L-function-1.23-18.fc26.aarch64.rpm 2017-02-14 08:01 139K fedora Mirroring Project L-function-devel- ...
- C# 各种类型的转换
/// <summary> /// 一些常用的方法 /// 1.一些高效的转换方法 /// </summary> public class Util { #region Obj ...
- 33 Introducing the Go Race Detector
Introducing the Go Race Detector 26 June 2013 Introduction Race conditions are among the most insidi ...