description stringlengths 35 9.39k | solution stringlengths 7 465k |
|---|---|
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
int n, m, q, sum[1001];
string s1, s2;
int main() {
cin >> n >> m >> q >> s1 >> s2;
for (int i = 1; i <= n; i += 1) {
sum[i] += sum[i - 1];
if (i > n - m + 1) {
continue;
}
bool f = true;
for (int j = i; j < i + m; j += 1) {
if (s1[j - 1]... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.util.*;
public class B48{
public static void main(String[] args){
Scanner inp=new Scanner(System.in);
int n=inp.nextInt();
int m=inp.nextInt();
int q=inp.nextInt();
String s=inp.next();
String t=inp.next();
if (n<m){
for(int i=0;i<q;i++){
System.out.println(0);
}
System.exit(0);
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | n,m,q = list(map(int,input().split()))
a = list(input())
b = list(input())
s = 0
starts = []
arr = []
for i in range(len(a) - len(b)+1):
if a[i:i+len(b)] == b:
arr.append(1)
s+=1
else:
arr.append(0)
starts.append(s)
for i in range(q):
l,r = list(map(int,input().split()))
if ... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.math.BigInteger;
import java.util.regex.*;
public class Myclass {
/*public static ArrayList a[]=new ArrayList[200001];
static boolean visited[]=new boolean [200001];
static long value[];
static long maxi[];
static long d... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #input
n, m, q = map(int, input().split())
s = input()
t = input()
#pre-process
dp = [0]*(n+1) #dp[x] : number of occurrences of t in s[0:x]
found_so_far = 0
for i in range(n-m+1):
if s[i:i+m] == t:
found_so_far += 1
dp[i+m] = found_so_far
#process query
for _ in range(q):
a, b = map(int, input().... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
int n, m, q;
char s[1005], t[1005];
int sum[1005];
int main() {
scanf("%d%d%d", &n, &m, &q);
scanf(" %s %s", s + 1, t + 1);
for (int i = 1; i <= n; i++) {
int good = 1;
for (int j = 1; j <= m; j++) {
if (s[i + j - 1] != t[j]) good = 0;
}
sum[i] =... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.util.*;
import java.io.*;
import java.text.*;
import java.math.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
import java.lang.Math.*;
public class segment_occurrences {
public static void main(String[] args) throws Exception {
new segment_occurrences().run();
}
public void ... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
int dp[2000];
char str[2000], tr[2000];
int main() {
int i, j, k, l, m, n, q;
scanf("%d%d%d", &n, &m, &q);
scanf("%s", str + 1);
scanf("%s", tr + 1);
for (int i = 1; str[i]; i++) {
for (j = 1, k = i; tr[j] && str[k]; j++, k++) {
if (tr[j] != str[k]) brea... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1001;
int a[maxn], cnt = 0;
char s1[maxn], s2[maxn];
int main() {
int n, m, q;
scanf("%d%d%d", &n, &m, &q);
cin >> s1 >> s2;
for (int i = 0; i < n; i++) {
if (s1[i] == s2[0]) {
bool fa = 1;
int now = i;
for (int j = 1; j < m; j... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import sys
n,m,q=map(int,sys.stdin.readline().split())
s=input()
t=input()
i=0
j=0
p=[0]*(n+1)
res = [i for i in range(len(s)) if s.startswith(t, i)]
for i in range(len(res)):
p[res[i]+1]=1
for i in range(2,n+1):
p[i]+=p[i-1]
#print(p)
for _ in range(q):
l,r=map(int,sys.stdin.readline().split())
r... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import os, sys
from io import BytesIO, IOBase
def main():
n, m, q = rints()
s, t, cum = rstr(), rstr(), []
for i in range(n - m + 1):
if s[i:i + m] == t:
cum.append((i + 1, i + m))
for i in range(q):
l, r = rints()
ans = 0
for l1, r1 in cum:
if ... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | n,m,q=map(int,input().split())
s=input()
t=input()
k=[0]*(n+1)
for i in range(1,n+1):
k[i]=k[i-1]
if s[i-1:i+m-1]==t:k[i]+=1
for i in range(q):
l,r=map(int,input().split())
print(k[max(l-1,r-m+1)]-k[l-1])
|
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | n,m, q = map(int, input().split())
s = str(input())
t = str(input())
def is_in(index):
if index + m > n:
return False
for j in range(m):
if not t[j] == s[index + j]:
return False
return True
precalc_ar_2 = [0 for i in range(n +1)]
in_was = [ False for i in range(... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | [n,m,q] = input().split()
n=int(n)
m=int(m)
q=int(q)
s=input()
t=input()
a=[0 for i in range(n + 5)]
for i in range(0,n-m+1):
if s[i:i+m]==t:
a[i + 1]=1
for i in range(1,n + 3):
a[i]+=a[i-1]
# print(a)
for i in range(q):
[l,r]=input().split()
l=int(l)
r=int(r)
# r-=1
# l-=1
# if ... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long z[3000019], arr[3000019], pre[3000019];
void fnc(string s) {
memset(z, 0, sizeof(z));
long long l = 0, r = 0;
long long n = s.size();
for (long long i = 1; i <= n; i++) {
if (i <= r) z[i] = min(r - i + 1, z[i - l]);
whil... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
int64_t n, m, q;
string s, t;
cin >> n >> m >> q >> s >> t;
vector<pair<int, int>> ins;
for (int i = 0; i < s.size(); ++i) {
if (i + t.size() - 1 < s.size() && s.substr(i, t.size()) == t) {
ins.push_back(make_pair... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.util.Scanner;
public class Contest {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = Integer.valueOf(in.next());
int m = Integer.valueOf(in.next());
int q = Integer.valueOf(in.next());
String s = in.next();
String t = in.next();
int[] ... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.io.*;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Scanner;
public class Main {
static int N=1010;
static int[] num=new int[N];
static int[] sum=new int[N];
static int n,m,k,q,tot,root,ans,ed;
static StreamTokenizer in=new StreamTokenizer(n... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual soluti... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, q;
cin >> n >> m >> q;
string s, t;
cin >> s >> t;
vector<int> I;
for (int i = 0; i < n - m + 1; i++) {
if (t == s.substr(i, m)) I.push_back(i);
}
for (int i = 0; i < q; i++) {
int l, r;
cin >> l >> r;
l--;
r--;
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | from sys import stdin, stdout
ti = lambda : stdin.readline().strip()
ma = lambda fxn, ti : map(fxn, ti.split())
ol = lambda arr : stdout.write(' '.join(str(i) for i in arr) + '\n')
os = lambda i : stdout.write(str(i) + '\n')
olws = lambda arr : stdout.write(''.join(str(i) for i in arr) + '\n')
import math
n, m, q = m... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m, q;
cin >> n >> m >> q;
string s, t;
cin >> s >> t;
vector<int> v;
for (int i = 0; i < int((s).size()); i++) {
int j;
for (j = 0; j < int((t).size()) && (i + j) < int((s).size()); j++) {
if (s[j + i] != t[j]) break;
}
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.StringTokenizer;
public class Main {
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
int n, m, q, dp[1010][1010];
char s[1010], t[1010];
bool used[1010];
int main() {
scanf("%d%d%d", &n, &m, &q);
scanf("%s", s + 1);
scanf("%s", t);
for (int i = 1; i + m - 1 <= n; i++) {
bool f = true;
for (int j = 0; j < m; j++) {
if (s[i + j] != t[j])... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | from sys import stdin, stdout
from itertools import repeat
def main():
n, m, q = map(int, stdin.readline().split())
s = stdin.readline().strip()
t = stdin.readline().strip()
dat = map(int, stdin.read().split(), repeat(10, 2 * q))
f = [-1]
for i, c in enumerate(t):
j = f[-1]
while... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | n, m, q = [int(x) for x in raw_input().split()]
s = raw_input()
t = raw_input()
idx = list()
if s[:m] == t:
idx.append(1)
else:
idx.append(0)
for i in xrange(1,n-m+1):
if s[i:i+m] == t:
idx.append(idx[i-1]+1)
else:
idx.append(idx[i-1])
for i in xrange(q):
l, r = [int(x)-1 for x in ... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, q;
cin >> n >> m >> q;
string s, t;
cin >> s >> t;
vector<bool> occ(n);
for (int i = 0; i < n; i++) {
if (s.substr(i, m) == t) {
occ[i] = 1;
}
}
vector<int> prefixOcc(n + 1);
prefixOcc[0] = 0;
for (int i = 1; i <= n; ... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | R=lambda:map(int,input().split())
n,m,q=R()
s,t=input(),input()
a=[0]
b=0
for i in range(n):b+=s[i:i+m]==t;a+=[b]
for _ in[0]*q:l,r=R();print(a[max(l-1,r-m+1)]-a[l-1])
# Made By Mostafa_Khaled |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.util.*;
import java.io.*;
public class SegmentOccurrences
{
public static void main(String[] p)
{
int n,m,q,i,j;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
m=sc.nextInt();
q=sc.nextInt();
int[] a=new int[n];
String s=sc.next();
String s1=sc.next();
HashSet<Integer> hs=new HashSet... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
string s, t;
long long m, n, q, dp[1010][1010];
int main() {
cin >> n >> m >> q;
cin >> s >> t;
for (int i = 0; i <= n - m; i++) {
bool b = false;
for (int j = i; j < i + m; j++) {
if (s[j] != t[j - i]) b = true;
}
if (b == false) {
dp[i][i... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
vector<long long> build(string s) {
int n = s.size();
vector<long long> kmp(n, 0);
for (int i = 1; i < n; i++) {
int j = kmp[i - 1];
while (j > 0 && s[i] != s[j]) {
j = kmp[j - 1];
}
if (s[i] == s[j]) j++;
kmp[i] = j;... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.util.Scanner;
public class B48Ecr{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int q = sc.nextInt();
String s = sc.next();
String s1 = sc.next();
int l = 0,r = 0,z = 0;
int a[] = new int[n];
for(int i = 0;i < n -... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... |
import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
private static final Comparator<? super Integer> Comparator = null;
static LinkedList<Integer> adj[];
static ArrayList<Integer> adj1[];
static int[] color,visited1;
static boolean b[],visited[],possible;
static int level[];
static ... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | from itertools import accumulate
from sys import stdin
# all_in = list(el.rstrip('\n') for el in stdin.readlines())
all_in = list(map(lambda x: x.rstrip('\n'), stdin.readlines()))
n, m, q = map(int, all_in[0].split())
s = all_in[1]
t = all_in[2]
l_r = [tuple(map(int, el.split())) for el in all_in[3:]]
in_ = [int(t =... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 20;
int sum[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, q;
cin >> n >> m >> q;
string s, t;
cin >> s >> t;
for (int i = 0; i < n; i++)
sum[i + 1] = sum[i] + (i + m <= n && s.substr(i, m)... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import re
from bisect import bisect_left as bl
from bisect import bisect_right as br
n, m, q = [int(x) for x in raw_input().split()]
s = str(raw_input())
t = str(raw_input())
a = [i.start() for i in re.finditer('(?=' + t + ')', s)]
# b = list(map(lambda x: int(x) + m, a))
for _ in xrange(q):
l, r = [int(x) for x ... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | ######### ## ## ## #### ##### ## # ## # ##
# # # # # # # # # # # # # # # # # # #
# # # # ### # # # # # # # # # # # #
# ##### # # # # ### # # # # # # # # #####
# # # # # # # # # # # # # # # # # #
#########... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... |
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
public class B {
public static void main(String[] srgs) {
Scanner nik = new Scanner(System.in);
int n = nik.nextInt();
int m = nik.nextInt();
int ... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | /* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
BufferedReader br... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | n,m,q=map(int,input().split())
s,t=input(),input()
a=[0,0]
b=0
for i in range(n):
b+=s[i:i+m]==t
a+=[b]
for _ in[0]*q:
l,r=map(int,input().split())
print(a[max(l,r-m+2)]-a[l])
|
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, q;
cin >> n >> m >> q;
string s;
cin >> s;
string t;
cin >> t;
string str1 = s;
size_t pos1;
vector<long long> arr;
pos1 = str1.find(t);
while (pos1 != string::npos) {
arr.push_back(pos1);
pos1 = str1.find(t, pos1 +... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | n,m,q = map(int,raw_input().split())
s = raw_input()
p = raw_input()
re = [0]*n
for i in xrange(0,n,1):
if i <n-m+1:
if s[i:i+m]==p:
re[i]=re[i-1]+1
else:
re[i]=re[i-1]
else:
re[i]=re[i-1]
re = [0]+re
#print re
for _ in xrange(q):
a,b=map(int,raw_input().split())
print re[max(a-1,b-m+1)]-re[a-1]
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | '''input
15 2 3
abacabadabacaba
ba
1 15
3 4
2 14
'''
n, m, q = [int(i) for i in input().split(" ")]
s = [i for i in input()]
t = [i for i in input()]
k = [0] * (n + 1)
for i in range(1, n + 1):
k[i] = k[i - 1]
if s[i - 1 : i + m - 1] == t:
k[i] += 1
for i in range(q):
l, r = [int(i) for i in input().split(" ")]
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | def f(l, r):
b = r - m + 1
if b < l:
ans = 0
else:
ans = a[l]
if b != n-1:
ans -= a[b + 1]
return ans
n, m, q = map(int, raw_input().split())
s = raw_input()
t = raw_input()
e = [0] * n
for i in range(n - m + 1):
if s[i:i + m] == t:
e[i] = 1
a = [0] * n
a[n-1] = e[n-1]
for i in rang... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | from bisect import insort,bisect_right,bisect_left
from sys import stdout, stdin, setrecursionlimit
from heapq import heappush, heappop, heapify
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from string import *
from queue import *
from math import *
from re imp... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.util.*;
import java.io.*;
public class Contest{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | def pref_func(s):
n = len(s)
f = list()
f.append(0)
for i in range(1,n):
j = f[i-1]
while j>0 and s[i] != s[j]:
j = f[j-1]
if s[i] == s[j]:
j += 1
f.append(j)
return f
n,m,q = list(map(int,input().split(' ')))
s = input()
t = input()
f = pref... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1e9 + 7;
const int64_t N = 2e6;
bool isQuery = false;
int64_t power(int64_t x, int64_t n) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return power(x, n / 2) * power(x, n / 2);
else
return x * power(x, n / 2) * power(x, n / 2);
}
int64_... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import itertools as it
n, m, q = map(int, input().split())
s, t = input(), input()
p = [int(s[i: i + len(t)] == t) for i in range(0, n - len(t) + 1)] + [0] * (len(t) - 1)
p = [0] + list(it.accumulate(p))
for _ in range(q):
left, right = map(int, input().split())
if right - left + 1 < len(t):
print(0... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | n, m, q = [int(i) for i in input().split()]
s = list(input())
t = list(input())
lt = len(t)
ls = len(s)
start = []
for i in range(ls - lt +1):
j = i
count = 0
while s[j] == t[count]:
j += 1
count += 1
if count >= lt:
break
if count == lt:
start.append(i + 1)
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main implements Runnable {
int maxn = (int)1e5+111;
int n,m,k;
long a[] = new long[maxn];
void solve() throws Exception {
int n = in.nextInt();
int m = in.nextInt();
int q = in.nextInt();
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
int st[1001];
int main() {
int n, m, q;
cin >> n >> m >> q;
string s;
cin >> s;
string t;
cin >> t;
st[0] = 0;
for (int i = 1; i <= n - m + 1; i++) {
bool b = true;
for (int j = i; j < i + m; j++) {
if (s.at(j - 1) != t.at(j - i)) {
b =... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.io.Writer;
impo... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | n, m, q = map(int, input().split())
x = [0 for i in range(n+1)]
b = input()
s = input()
for i in range(n-m+1):
f = True
for j in range(i, i+m):
if b[j] != s[j-i]:
f = False
break
if f:
x[i+m] = 1
for i in range(1, n+1):
x[i] = x[i] + x[i-1]
x += [x[-1] for i in ra... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import sys
out = sys.stdout
n, m, q = map(int,input().split())
s = input()
t = input()
res = []
for i in range(n-m+1):
if s[i:i+m] == t:
e = (i, i+m-1)
res.append(e)
for i in range(q):
li, ri = map(int, input().split())
k = 0
for t, p in res:
if t >= (li - 1) and p <= (ri - 1):
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.util.*;
import java.lang.*;
import java.io.*;
/*
*
* Comments Here
*
*/
public class E49_B
{
static BufferedReader br;
static BufferedWriter bw;
static StringTokenizer st;
public static void main(String[] args) throws java.lang.Exception
{
br = new BufferedReader(new InputStreamReader(Syste... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
long long const MOD = 1e9 + 7;
long long const N = 1e3 + 10;
long long ara[N + 1];
long long bra[N + 1];
int main() {
(ios_base::sync_with_stdio(false), cin.tie(NULL));
long long n, m, q;
cin >> n >> m >> q;
string str, s;
cin >> str >> s;
for (long long i = 0; ... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Solution {
static class BinaryIndexTree {
private int[] array;
private int total;
public BinaryIndexTree(i... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
int n, m, q, lct1, lct2;
string s, t;
int z[3005];
int cnt;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m >> q;
cin >> s >> t;
s = t + s;
int len = s.length();
z[0] = 0;
for (int i = 1, l = 0, r = 0; i < len; ++i) ... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class SegmentOccurrences {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Stri... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
struct Node {
int d;
struct Node *left, *right;
};
int p[1000][1000] = {0};
string s, t;
void dp(int i, int j) {
if (j - i + 1 == t.size()) {
int f = 1;
for (int z = 0; z < t.size(); z++) {
if (s[i + z] != t[z]) {
f = 0;
break;
}
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
string s, t;
vector<int> can;
int n, m, k;
int main() {
cin >> n >> m >> k;
cin >> s >> t;
for (int i = 0; i <= n - m; i++) {
if (s.substr(i, m) != t) continue;
can.push_back(i + 1);
}
while (k--) {
int l, r;
cin >> l >> r;
r = r - m + 1;
i... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
int n, m, q, l, r, vf, ans, i, j, k;
const int LMAX = 1e3;
char s[LMAX + 5], t[LMAX + 5];
int st[LMAX + 5], dr[LMAX + 5], cnt = 0;
int main() {
cin >> n >> m >> q;
for (i = 1; i <= n; i++) cin >> s[i];
for (i = 1; i <= m; i++) cin >> t[i];
for (i = 1; i <= n - m + 1... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | # cook your code here
n,m,q=map(int,raw_input().split())
s=raw_input()
t=raw_input()
pre=[0]*(n+1)
for i in xrange(n-m+1):
j=0
k=i
pre[i+1]=pre[i]
while(j<m):
if t[j]==s[k]:
j+=1
k+=1
else: break
if j==m: pre[i+1]+=1
for i in xrange(q):
l,r=map(int,ra... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s, t;
int n, m, q, ct = 0, flag, l, r;
cin >> n >> m >> q;
vector<vector<int>> ans(n + 1, vector<int>(n + 1, 0));
cin >> s;
cin >> t;
for (int i = 0; i < n; i++) {
flag = 1;
for (... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | n, m, q = map(int, input().split())
s = input()
t = input()
a = [0] * (n + 1)
for i in range(n - m + 1):
if s[i:i + m] == t:
a[i + 1] += 1
S = [0] * (n + 1)
for i in range(1, n + 1):
S[i] += S[i - 1] + a[i]
for i in range(q):
l, r = map(int, input().split())
if r + 1 - l >= m:
print(S... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
string str;
vector<int> z;
int len = 0;
void zfunc() {
len = str.size();
z.resize(len);
int ind = 0;
for (int i = 1; i < len; i++) {
if (ind + z[ind] - 1 >= i) {
z[i] = min(ind + z[ind] - i, z[i - ind]);
}
for (; i + z[i] < len && str[i + z[i]] == ... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
public class Main{
static class MyScanner {
Bu... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
MyReader reader = new MyReader(System.in);
// MyReader reader = new MyReader(new FileInputStream("input.txt"));
MyWriter writer = new MyWriter(S... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.util.* ;
import java.io.BufferedReader ;
import java.io.InputStreamReader ;
public class SegmentOccurrences
{
private static final boolean debug = false ;
public static void main(String args[]) throws Exception
{
// String T = "aanonoaanonoaanono" ;
// String P = "aa" ;
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class Problem1016B {
public static void main(String[] args) throws Exc... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | n, m, k = map(int, input().split())
s = input()
st = input()
ar = [0 for i in range(n)]
pr = [0 for i in range(n+1)]
for i in range(n-m+1):
found = 1
for j in range(m):
if s[i+j] != st[j]:
found = 0
break
ar[i] = found
pr[i+1] = pr[i]+ ar[i]
for i in range(max(0, ... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')
n,m,q = m... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | n,m,q = map(int, raw_input().split())
a = raw_input()
b = raw_input()
wynik = ''
for i in range(0, n - m + 1):
if a[i : i + m] == b:
wynik += '1'
else: wynik += '0'
for i in range(q):
x , y = map(int, raw_input().split())
if y - x + 1 >= m:
print(wynik[x - 1 : y - m + 1].count('1'))
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.util.*;
public class A
{
public static void main(String ar[])
{
Scanner s=new Scanner(System.in);
int n=s.nextInt(); int m=s.nextInt(); int q=s.nextInt(); s.nextLine();
char c[]=s.nextLine().toCharArray();
char d[]=s.nextLine().toCharArray();
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
char s[100005], t[100005];
int Q, m, n, l1, l2;
int sum[100005], fr[100005], ma[100005];
void init() {
int i, np;
scanf("%d%d%d", &l1, &l2, &Q);
scanf("%s", s);
scanf("%s", t);
for (i = l1; i > 0; i--) s[i] = s[i - 1];
for (i = l2; i > 0; i--) t[i] = t[i - 1];
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | def main():
(n,m,q) = [int(x) for x in input().split()]
s = input()
t = input()
st1 = [0 for i in range(n+1)]
st2 = [0 for i in range(n+1)]
for i in range(m,n+1) :
if t == s[i-m:i] :
st1[i-m+1] = 1
st2[i-1]=1
for i in range(1,n+1) :
st1[i] = st1[i-1]+s... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.Writer;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author palayutm
*/
pub... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
long long ans[1005];
int main() {
long long n, m, k;
string a, b;
cin >> n >> m >> k;
cin >> a >> b;
for (int i = 0; i <= n - m; i++) {
ans[i + 1] = ans[i] + (a.substr(i, m) == b);
}
while (k--) {
long long l, r;
cin >> l >> r;
if (r - l + 1 < ... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | /* Author: Ronak Agarwal, reader part not written by me*/
import java.io.* ; import java.util.* ;
import static java.lang.Math.min ; import static java.lang.Math.max ;
import static java.lang.Math.abs ; import static java.lang.Math.log ;
import static java.lang.Math.pow ; import static java.lang.Math.sqrt ;
/* Thread i... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | n, m, q = map(int, input().split())
s = input()
t = input()
a = [0] * n
for i in range(n - m + 1):
if s[i:i + m] == t:
a[i] = 1
for i in range(q):
k = 0
l, r = map(int, input().split())
for j in range(l - 1, r):
if a[j] == 1 and j + m - 1 < r:
k += 1
print(k) |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
int main() {
int n, q, g;
int index;
int a[1005];
int k = 0;
string s, t;
string ss[1005];
scanf("%d%d%d", &n, &q, &g);
getchar();
cin >> s >> t;
for (int i = 0; i < n; i++) {
string str = s.substr(i, q);
if (str == t)... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.util.*;
public class B
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int m = input.nextInt();
int q = input.nextInt();
input.nextLine();
String s = input.nextLine();
String t = input.nextLine();
int[] occurences = new i... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #####################################
import atexit, io, sys, collections
buffer = io.BytesIO()
sys.stdout = buffer
@atexit.register
def write(): sys.__stdout__.write(buffer.getvalue())
#####################################
import collections, math
n,m,qq = map(int, raw_input().split())
def f(u,v,dp):
u = m... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
int arr[1001] = {0};
int u[200001] = {0};
int main() {
ios::sync_with_stdio(false);
int n, m, q, i, l, r;
cin >> n >> m >> q;
string s, t, ch;
cin >> s >> t;
int pos = -1, x = 0;
while (pos + 1 < s.size() && s.find(t, pos + 1) != string::npos) {
pos = s.fi... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
;
const double eps = 1e-8;
const int mod = 10007;
const int maxn = 1e6 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f;
const unsigned long long p = 2333;
int n, m, q, l, r, ans;
unsigned long long hs[1007], ht, pw[1007];
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | n,m,q=map(int,input().split())
s=str(input())
t=str(input())
arrx=[]
i=0
count=0
while(i<n):
if(s[i]==t[0]):
j=0
while(j+i<n and j<m and s[j+i]==t[j]):
j+=1
if(j==len(t)):
count+=1
arrx.append(count)
i+=1
for i in range(q):
x,y=map(int,input().split())
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import sys
import itertools
input = sys.stdin.readline
def main():
N, M, Q = [int(x) for x in input().split()]
S = input().strip()
T = input().strip()
LR = [[int(x) for x in input().split()] for _ in range(Q)]
ans = [0] * (N + 1)
for i in range(N):
if S[i:i + M] == T:
ans[... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
inline int two(int n) { return 1 << n; }
inline void set_bit(int& n, int b) { n |= two(b); }
inline void unset_bit(int& n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
template <class T>
T gcd(T a, T b) {
return (b != 0 ? gcd<T>(b, a % b) : a);... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | from bisect import bisect_left, bisect_right
n, m, q = map(int, raw_input().split(" "))
s = raw_input()
t = raw_input()
def occurrences(string, sub):
count = start = 0
starts = []
while True:
start = string.find(sub, start)
if start >= 0:
starts.append(start)
start ... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | '''input
10 3 4
foreforfor
for
1 3
1 10
5 6
5 7
'''
from collections import defaultdict as df
from bisect import bisect_left as bl
from random import randint as R
import sys
def gcd(a,b):
if b==0:
return a
return gcd(b,a%b)
mod=10**9+7
def brute(a,b,n):
return gcd(pow(a,n)+pow(b,n),abs(a-b))%mod
def good(a,b... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
int n, m, q;
char a[1005], b[1005];
struct qujian {
int s, e;
};
qujian qq[10005];
int num = 0;
int main() {
scanf("%d%d%d", &n, &m, &q);
scanf("%s\n%s", a, b);
if (n < m) {
for (int i = 0; i < q; i++) {
int x, y;
scanf("%d%d", &x, &y);
printf(... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;
public class cf1016b {
public static void main(String[] args) {
FastScanner in = new FastScanner(System.in);
int N = in.nextInt();
int M = in.nextInt();
int Q = in.nextInt();
char[] s = in.next().toCharArray();... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import sys
sys.setrecursionlimit(2000)
from collections import Counter
from functools import reduce
# sys.stdin.readline()
if __name__ == "__main__":
# single variables
n, m, q = [int(val) for val in sys.stdin.readline().split()]
s = input()
t = input()
count = [int(s[i:i+m]==t) for i in range(n)]... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
string s1, s2;
int ans[maxn];
int main() {
int n, m, q;
cin >> n >> m >> q;
cin >> s1 >> s2;
memset(ans, 0, sizeof(ans));
for (int i = 0; i + m <= n; i++) {
if (s1.substr(i, m) == s2) {
ans[i + 1]++;
}
}
for (int i = 1;... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
int const lmt = 1e5 + 4;
long long pre[lmt];
int main() {
int n, m, q;
cin >> m >> n >> q;
string s, t;
cin >> s >> t;
string tt = t + '#' + s;
int len = tt.length();
int f[len];
int j = 0;
f[0] = 0;
for (int i = 1; i < len; i++) {
j = f[i - 1];
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | import bisect
f=lambda: map(int, input().split())
n,m,q=f()
s,t=input(),input()
x,st=[],[]
c1=0
for i in range(n):
if "".join(c for c in s[i:i+m])==t:
x.append(i+1)
c1+=1
for i in range(q):
cnt=0
l,r=f()
if x!=[] and r-l+1>=m:
r=r-m+1
left=bisect.bisect_left(x,l)
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | #include <bits/stdc++.h>
using namespace std;
string s, t;
int n, m, q;
int v[100000] = {};
void match() {
for (int i = 0; i <= n - m; i++) {
v[i + 1] = v[i] + (s.substr(i, m) == t);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
cin >> n >> m >> q;
cin >> s;
cin >> ... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | n, m, q = list(map(int, input().strip().split()))
s = input()
t = input()
locs = []
for i in range(n):
if i + m <= n and s[i:i+m] == t:
locs.append(i)
#print(locs)
def find_max(nums, target):
l, r = 0, len(nums) - 1
while l < r:
mid = (l + r) // 2
if nums[mid] >= target:
... |
You are given two strings s and t, both consisting only of lowercase Latin letters.
The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order.
Each of the occurrences of string a in a string b is a position i (1 β€ i β€ |b| - |a| + 1) such that b[i..i... | from collections import defaultdict
n, m, q = [int(i) for i in input().split()]
s = input()
t = input()
x = []
sums = [0 for i in range(n)]
for i in range(q):
x.append([int(i) - 1 for i in input().split()])
for i in range(n):
if i - m + 1 >= 0:
if s[i - m + 1:i + 1] == t:
sums[i] += 1
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.