当前位置:网站首页>【集训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;
}
边栏推荐
猜你喜欢

干货!迈向鲁棒的测试时间适应

Qt 之 QDateEdit 和 QTimeEdit

&& 不是此版本的有效语句分隔符

Travel with Shengteng: See all the AI attractions in Jinling City in one day

新增一地公布2022下半年软考报考时间

金仓数据库 KingbaseGIS 使用手册(6.5. 几何对象编辑函数)

Live Preview | ICML 2022 11 first-author scholars share online neural network, graph learning and other cutting-edge research

kubesphere

Mysql集群 ShardingSphere

离散选择模型之Gumbel分布
随机推荐
生成NC文件时,报错“未定义机床”
【诗歌】爱你就像爱生命
2022-08-09 mysql/stonedb-subquery performance improvement-introduction
【Burning】It's time to show your true strength!Understand the technical highlights of the 2022 Huawei Developer Competition in one article
【实用工具系列】MathCAD入门安装及快速上手使用教程
Forbidden (CSRF token missing or incorrect.): /
【诗歌】枕上诗书
Redis集群
68. qt quick-qml multi-level folding drop-down navigation menu supports dynamic add/unload, support qml/widget loading, etc.
Click: 377. Combined Sum Ⅳ
杭电多校-Counting Stickmen-(思维+组合数+容斥)
JS--hashchange事件--使用/教程
力扣:322. 零钱兑换
金仓数据库 KingbaseGIS 使用手册(6.5. 几何对象编辑函数)
What are the Shenzhen fortress machine manufacturers?Which one do you recommend?
【哲理】读书的意义
数据库优化 | 干货
正则表达式的实际使用
Filament-Material 绘制基本图形
【面试高频题】可逐步优化的链表高频题