当前位置:网站首页>【集训DAY4】询问【Hash】
【集训DAY4】询问【Hash】
2022-08-09 22:35:00 【VL——MOESR】
思路:
我们把字符串拆成26个01穿来记录每个字符的位置
然后用字符串hash判断就行了
c o d e code code
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int n, m;
char s[200010];
unsigned long long h[26][200010], p[200010], a[26], b[26];
unsigned long long get_(int i, int l, int r) {
return h[i][r] - h[i][l - 1] * p[r - l + 1];
}
int main() {
scanf("%d%d", &n, &m);
scanf("%s", s + 1);
p[0] = 1;
for(int i = 1; i <= n; i ++) p[i] = p[i - 1] * 7;
for(int i = 0; i < 26; i ++)
for(int j = 1; j <= n; j ++)
h[i][j] = h[i][j - 1] * 7 + (s[j] == 'a' + i) * 3;
while(m --) {
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
for(int i = 0; i < 26; i ++) {
a[i] = get_(i, x, x + z - 1);
b[i] = get_(i, y, y + z - 1);
}
sort(a, a + 26);
sort(b, b + 26);
bool flag = 1;
for(int i = 0; i < 26; i ++)
if(a[i] != b[i]) {
flag = 0;
break;
}
if(flag) printf("YES\n");
else printf("NO\n");
}
return 0;
}
边栏推荐
猜你喜欢
随机推荐
70. Stair Climbing Advanced Edition
【实用工具系列】MathCAD入门安装及快速上手使用教程
YGG 经理人杯总决赛已圆满结束,来看看这份文字版总结!
为什么刀具数据库无法打开?
String类常用方法
用函数统计最长单词的字母数量
How to know the computer boot record?
&& 不是此版本的有效语句分隔符
《GB5084-2021》PDF下载
国内BI厂商一览
Click: 377. Combined Sum Ⅳ
2022牛客暑期多校训练营6(ABGIJM)
Force Buckle: 474. Ones and zeros
SRv6 performance measurement
harbor配置远程仓库
What are the Shenzhen fortress machine manufacturers?Which one do you recommend?
What are the basic steps to develop a quantitative trading strategy?
测试2年,当时身边一起入行的朋友已经月薪20k了,自己还没过万,到底差在了哪里?
力扣:322. 零钱兑换
MQTT X Web:在线的 MQTT 5.0 客户端工具