【CF1016B】Segment Occurrences(模拟)
2024-09-03 18:06:57
题意:给定两个串s和t,多次询问s的一个区间[l ,r]中有多少个子串与t串相同
len<=1e3,q<=1e5
思路:前缀和
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define MOD 1000000007
#define N 210000 char a[N+],b[N+];
int s[N+];
ll n,m,q; int read()
{
int v=,f=;
char c=getchar();
while(c<||<c) {if(c=='-') f=-; c=getchar();}
while(<=c&&c<=) v=(v<<)+v+v+c-,c=getchar();
return v*f;
} int main()
{
//freopen("2.in","r",stdin);
//freopen("2.out","w",stdout);
scanf("%d%d%d",&n,&m,&q);
scanf("%s",a+);
scanf("%s",b+);
for(int i=;i<=N-;i++) s[i]=;
for(int i=m;i<=n;i++)
{
int flag=;
for(int j=;j<=m;j++)
if(b[m-j+]!=a[i-j+]){flag=;break;}
s[i]=s[i-]+flag;
}
for(int i=;i<=q;i++)
{
int x,y;
scanf("%d%d",&x,&y);
int t;
if(y-x+<m) t=;
else t=s[y]-s[x+m-];
printf("%d\n",t);
}
return ;
}
最新文章
- C语言的可变参数在Linux(Ubuntu)与Windows下注意点
- visual studio2015使用git管理源代码
- 赴美工作常识(Part 3 - 英语)
- android Activity runOnUiThread() 方法使用
- CF# 334 Alternative Thinking
- 【EF Code First】CodeFirst初始配置
- 《Linux命令行大全》系列(一、shell是什么)
- hdu 1175 连连看 DFS
- php同时循环两个数组
- iOS 网络与多线程--8.百度地图的使用(调用系统浏览器)
- 【转】RTSP协议学习笔记
- WorkFlow4.0--入门到精通系列-专题索引
- 比较实用的webpack配置代码
- webpack学习(一):webpack 介绍&;安装&;常用命令
- Leetcode_58_Length of Last Word
- mac 上安装 nvm 遇到的坑
- node环境配置
- fair scheduler配置
- jquerymobile动态添的无索刷新
- 田螺便利店—win10专业版激活码