题意:给定两个串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 ;
}

最新文章

  1. C语言的可变参数在Linux(Ubuntu)与Windows下注意点
  2. visual studio2015使用git管理源代码
  3. 赴美工作常识(Part 3 - 英语)
  4. android Activity runOnUiThread() 方法使用
  5. CF# 334 Alternative Thinking
  6. 【EF Code First】CodeFirst初始配置
  7. 《Linux命令行大全》系列(一、shell是什么)
  8. hdu 1175 连连看 DFS
  9. php同时循环两个数组
  10. iOS 网络与多线程--8.百度地图的使用(调用系统浏览器)
  11. 【转】RTSP协议学习笔记
  12. WorkFlow4.0--入门到精通系列-专题索引
  13. 比较实用的webpack配置代码
  14. webpack学习(一):webpack 介绍&amp;安装&amp;常用命令
  15. Leetcode_58_Length of Last Word
  16. mac 上安装 nvm 遇到的坑
  17. node环境配置
  18. fair scheduler配置
  19. jquerymobile动态添的无索刷新
  20. 田螺便利店—win10专业版激活码

热门文章

  1. linux下libnet编程 亲自测试可用
  2. 2d游戏中的射线与矩形检测碰撞
  3. (转发)IOS高级开发~Runtime(三)
  4. JavaScript之基操
  5. 在VMware上安装centos7
  6. Laravel核心解读--Console内核
  7. python3中urllib库的request模块详解
  8. LeetCode(134) Gas Station
  9. Educational Codeforces Round 53 (Rated for Div. 2) C Vasya and Robot 二分
  10. 小甲鱼零基础入门PYTHON