【CF1016B】Segment Occurrences(模拟)
题意:给定两个串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 ;
}
【CF1016B】Segment Occurrences(模拟)的更多相关文章
- Educational Codeforces Round 48 (Rated for Div. 2) B 1016B Segment Occurrences (前缀和)
B. Segment Occurrences time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Segment Occurrences(string find函数)
Description You are given two strings s and t, both consisting only of lowercase Latin letters.The s ...
- 1016B - Segment Occurrences(字符串的匹配)
题意:字符串a,字符串b,给你q个区间,让你求a的区间内字符串b出现了多少次 之前用的前缀数组做的,没想起来,发现这个其实也可以 #include<cstdio> #include< ...
- Educational Codeforces Round 48
题目地址 Edu48 A.Death Note 翻译 你有一个无穷页的本子,每一页可以写\(m\)个名字, 你在第\(i\)天要写\(a_i\)个名字,如果这一页恰好写满了,你就会翻页, 问每天的翻页 ...
- Codeforces Edu Round 48 A-D
A. Death Note 简单模拟,可用\(\%\)和 \(/\)来减少代码量 #include <iostream> #include <cstdio> using nam ...
- HGOI20180817 (NOIP模拟Day1 task)
HGOI自测 初测:150=80+20+50 rank1~rank3(并列3个rank1,所以我是rank3 qwq) 今日分突然想简约 CF359A Table https://www.luogu. ...
- 基于UDP协议模拟的一个TCP协议传输系统
TCP协议以可靠性出名,这其中包括三次握手建立连接,流控制和拥塞控制等技术.详细介绍如下: 1. TCP协议将需要发送的数据分割成数据块.数据块大小是通过MSS(maximum segment siz ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 填坑*** WARNING L15: MULTIPLE CALL TO SEGMENT
填坑*** WARNING L15: MULTIPLE CALL TO SEGMENT 警告:发生了重入! 解释:在主循环里调用了一个函数,而在中断服务中又一次调用了同样的函数.当主循环运行到该函数中 ...
随机推荐
- Java(面试题):字符串截取
在Java中,字符串“abcd”与字符串“ab你好”的长度是一样,都是四个字符. 但对应的字节数不同,一个汉字占两个字节. 定义一个方法,按照指定的字节数来取子串. 如:对于“ab你好”,如果取三个字 ...
- 关于lua 5.3 服务端热更新流程
脚本的热更新的流程都大同小异, 第一步先保存旧代码的块的数据, 第二部加载新的代码块,第三步将旧代码块的局部和全局数据拷贝到新代码块的对应的 变量中. 在服务器热更新中,主要考虑热更的内容是什么, 一 ...
- 【转】嵌入式操作系统VxWorks中TFFS文件系统的构建
时间:2005-02-20 来源:21IC中国电子网 作者:771所加固机工程部 蔡本华 高文炜 关键字:VxWorks TFFS 嵌入式操作系统 文件系统 摘要:目前的嵌入式 ...
- DNS 工作原理是什么,域名劫持、域名欺骗、域名污染又是什么
DNS 工作原理是什么,域名劫持.域名欺骗.域名污染又是什么 2014年11月27日 10:05:40 阅读数:6726 标签: dns网络互联网顶级域名递归 更多 个人分类: 网络学习 一.DN ...
- Linux - 链接概念详解
1> Linux链接概念Linux链接分两种,一种被称为硬链接(Hard Link),另一种被称为符号链接(Symbolic Link).默认情况下,ln命令产生硬链接. [硬连接]硬连接指通过 ...
- python入门:最基本的用户登录
#! usr/bin/env python # -*- coding: utf-8 -*- #最基本的用户登录 import getpass usre = input("username:& ...
- 【android】安卓平台版本和API版本的对应关系
安卓平台版本和API版本对应关系
- 【nginx】 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
2013/10/22 20:05:49 [error] 12691#0: *6 FastCGI sent in stderr: "Primary script unknown" w ...
- 【Hadoop/Hive/mapreduce】系列之使用union all 命令之后如何对hive表格使用python进行去重
业务场景大概是这样的,这里由两个hive表格,tableA 和 tableB, 格式内容都是这样的: uid cate1 cate2 在hive QL中,我们知道union有着自动去重的功能,但是那是 ...
- Html5_css
CSS 在标签上设置style属性: background-color: #2459a2; height: 48px; ... 编写css样式: 1. 标签的style属性 2. 写在head里面 s ...