当前位置:网站首页>【集训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;
}
边栏推荐
- A summary of 6 common tools for cross-border e-commerce
- tiup cluster template
- [Interface Test] Decoding the request body string of the requests library
- 用哈希简单封装unordered_map和unordered_set
- MVC与MVVM模式的区别
- ABAP中Collect的用法
- Day 12 of learning to program
- Pytorch分布式训练/多卡训练DDP——模型初始化(torch.distribute 与 DDP的区别)
- Click: 518. Change Exchange II
- 深圳堡垒机厂家有哪些?重点推荐哪家?
猜你喜欢

The latest "Grain Academy Development Tutorial" in 2022: 10 - Front-end payment module

生成NC文件时,报错“未定义机床”

首席信息官如何将可持续性和技术结合起来

Explore the TiDB Lightning source code to solve the found bugs

2022-08-09 mysql/stonedb-子查询性能提升-概论

一体化伺服电机在三轴钻孔机中的应用

How to match garbled characters regularly?

完全背包理论

多商户商城系统功能拆解24讲-平台端分销会员

新增一地公布2022下半年软考报考时间
随机推荐
torch.distributed多卡/多GPU/分布式DPP(二)——torch.distributed.all_reduce(reduce_mean)&barrier&控制进程执行顺序&随机数种子
70. 爬楼梯进阶版
《GB5084-2021》PDF下载
Cmake 用法记录
LeetCode952三部曲之三:再次优化(122ms -> 96ms,超51% -> 超91%)
了解什么是架构基本概念和架构本质
用函数统计最长单词的字母数量
[Cloud Native] This article explains how to add Tencent Crane to Kubevela addon
LiveData : Transformations.map and Transformations.switchMap usage
HStreamDB v0.9 发布:分区模型扩展,支持与外部系统集成
【诗歌】最高级的惩罚就是沉默
【JZOF】77 Print binary tree in zigzag
tiup cluster stop
高手这样看现货白银走势图
【哲理】事教人
MVC与MVVM模式的区别
经济衰退即将来临前CIO控制成本的七种方法
技术盛宴!华云数据携六大议题亮相OpenInfra Days China
外包的水有多深?腾讯15k的外包测试岗能去吗?
Redis集群