当前位置:网站首页>【集训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;
}
边栏推荐
- 外包的水有多深?腾讯15k的外包测试岗能去吗?
- 力扣:322. 零钱兑换
- Click: 518. Change Exchange II
- 恭喜获奖得主 | 互动有礼获赠 Navicat Premium
- k8s部署mysql
- Day 12 of learning to program
- Gold Warehouse Database KingbaseGIS User Manual (6.2. Management Functions)
- 【面试高频题】可逐步优化的链表高频题
- Miscellaneous talk - the sorrow of programmers
- matplotlib散点图自定义坐标轴(文字坐标轴)
猜你喜欢
随机推荐
torch.distributed多卡/多GPU/分布式DPP(二)——torch.distributed.all_reduce(reduce_mean)&barrier&控制进程执行顺序&随机数种子
tiup cluster start
complete knapsack theory
【诗歌】被讨厌的勇气
Live Preview | ICML 2022 11 first-author scholars share online neural network, graph learning and other cutting-edge research
shader学习笔记(五)
【诗歌】枕上诗书
2022-08-09 mysql/stonedb-subquery performance improvement-introduction
【实用工具系列】MathCAD入门安装及快速上手使用教程
金仓数据库 KingbaseGIS 使用手册(6.5. 几何对象编辑函数)
力扣:279.完全平方数
领跑政务云,连续五年中国第一
为什么刀具数据库无法打开?
Leetcode 98. 验证二叉搜索树
ALV报表总结2022.8.9
【JZOF】77 Print binary tree in zigzag
kubesphere
[Cloud Native] This article explains how to add Tencent Crane to Kubevela addon
leetcode 20. Valid Parentheses 有效的括号(中等)
Cmake 用法记录