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\) 的所有点权 ...
随机推荐
- 缓存失效策略(FIFO,LRU,LFU)
当缓存需要被清理时(比如空间占用已经接近临界值了),需要使用某种淘汰算法来决定清理掉哪些数据.常用的淘汰算法有下面几种: 1. FIFO:First In First Out,先进先出.判断被存储的时 ...
- axios post 踩坑之 post传参
今天在项目(vue2.0)使用axios进行post请求的时候,使用官方文档的格式传递给后台的数据是一整个json对象,参数已经传递出去了,但是后台获取不到,() 解决方法 利用aixos结合qs来解 ...
- MongoDB - Introduction to MongoDB, Databases and Collections
MongoDB stores BSON documents, i.e. data records, in collections; the collections in databases. Data ...
- 部署elasticsearch遇到的问题
为增加搜索功能,最近在自己的服务器上部署elasticsearch,折腾一下,把注意的问题记录一下. 1. 因为最近的es5.5.2要求java1.8,所以确保java版本正确. 2. 我的服务器只 ...
- Linux基础-host文件解析
任务目标:为集群内的机器设定主机名,利用/etc/hosts文件来解析自己的集群中所有的主机名, 相应的集群的配置应该改成使用主机名的方式 使用 hostnamectl set-hostname 设定 ...
- python端口扫描
简易版: #author:Blood_Zero #coding:utf-8 import socket import sys PortList=[21,22,23,25,80,135] # host= ...
- linux===sar命令性能监控
sar介绍: sar是System Activity Reporter(系统活动情况报告)的缩写.sar工具将对系统当前的状态进行取样,然后通过计算数据和比例来表达系统的当前运行状态.它的特点是可以连 ...
- C#基础学习之FileStream
FileStream和File的区别 后者比前者给内存带来压力大. FileStream可以操作字节也就是可以保存任何类型的文件. 1.FileStream读文件操作 //OpenOrCreate: ...
- Jenkins忘记用户名密码
一.进入C盘.jenkins配置文件中找到config.xml 需要删除一下内容: <useSecurity>true</useSecurity> <authorizat ...
- 两个Bounding Box的IOU计算代码
Bounding Box的数据结构为(xmin,ymin,xmax,ymax) 输入:box1,box2 输出:IOU值 import numpy as np def iou(box1,box2): ...