Search is not available for this dataset
name stringlengths 2 112 | description stringlengths 29 13k | source int64 1 7 | difficulty int64 0 25 | solution stringlengths 7 983k | language stringclasses 4
values |
|---|---|---|---|---|---|
1016_B. Segment Occurrences | 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... | 2 | 8 | n, m, q = list(map(int, input().split()))
s = list(input())
t = list(input())
a = [list(map(int, input().split())) for i in range(q)]
if n < m:
for i in range(q):
print(0)
exit()
res = [0] * (n - m + 1)
for i in range(n - m + 1):
if s[i:(i + m)] == t:
res[i] = 1
for u in range(q):
l =... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | import sys
from array import array
def readline(): return sys.stdin.buffer.readline().decode('utf-8')
n, m, q = map(int, readline().split())
s, t = '*' + readline().rstrip(), readline().rstrip()
dp_r = [0]*(n+1)
dp_l = [0]*(n+1)
for i in range(m, n+1):
if s[i-m+1:i+1] == t:
dp_r[i] = 1
dp_l[i-m... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class SegmentOccurrences {
static class MyScanner {
private BufferedReader br;
private StringTokenizer st;
MyScanner() {
br = new BufferedReader... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | from __future__ import print_function,division
import sys
if sys.version_info < (3, 0):
range = xrange
input = sys.stdin.readline
class SegmentSum:
def __init__(S,n):
sz = 1
while sz < n: sz <<= 1
S.data = [0]*(n + sz)
S.sz = sz
def sum(S,l,r):
sz = S.sz
da... | PYTHON |
1016_B. Segment Occurrences | 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... | 2 | 8 | n,m,q=map(int,input().split())
a=input()
b=input()
flags=[0]*(1007)
pr=[0]*(1007)
for i in range(n-m+1):
f=1
for j in range(m):
if a[i+j]!=b[j]:
f=0
flags[i]=f
pr[i+1]=pr[i]+flags[i]
for i in range(max(0,n-m+1),n):
pr[i+1]=pr[i]
for i in range(q):
l,r=map(int,input().split(... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 |
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class edu {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
ArrayList<Integer> list=new ArrayList<Integer>();
int n=i... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | #coding:utf-8
tmp = raw_input()
n = int(tmp.split()[0])
m = int(tmp.split()[1])
q = int(tmp.split()[2])
s = raw_input()
t = raw_input()
st = [0]*n
for i in range(n-m+1):
if t == s[i:i+m]:
st[i] += 1
data = []
res = []
for i in range(q):
da = [int(i) for i in raw_input().split()]
L = da[0]
R = da[1]
cnt = 0
if L... | PYTHON |
1016_B. Segment Occurrences | 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... | 2 | 8 | /***
* ██████╗=====███████╗====███████╗====██████╗=
* ██╔══██╗====██╔════╝====██╔════╝====██╔══██╗
* ██║==██║====█████╗======█████╗======██████╔╝
* ██║==██║====██╔══╝======██╔══╝======██╔═══╝=
* ██████╔╝====███████╗====███████╗====██║=====
* ╚═════╝=====╚══════╝====╚══════╝====╚═╝=====
* ===... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 |
m, n, x = raw_input().split()
s = raw_input()
t = raw_input()
m, n, x = int(m), int(n), int(x)
class TreeNode(object):
def __init__(self, l, r):
self.left = None
self.right = None
self.interval = (l, r)
self.val = 0
def build(start, end):
# print start, end
node = TreeNode... | PYTHON |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.util.*;
import java.io.*;
public class Main
{
public static void main(String args[])
{
// int n,m;
{
Scanner sc= new Scanner(System.in);
int n= sc.nextInt();
int m= sc.nextInt();
int q= sc.nextInt();
String s=sc.next();
String t= sc.next();
int ns= s.length();
int nt= t.leng... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | n, m, q = map(int, input().split())
a = input()
b = input()
c = [0]
for i in range(1, n + 1):
# print(a[max(i - m, 0):i])
c.append(c[i - 1] + (a[max(i - m, 0):i] == b))
# print(c)
for i in range(q):
l, r = map(int, input().split())
if r - l >= m - 1:
print(max(c[r] - c[l + m - 2], 0))
else:... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | n,m,q = map(int, input().split())
s = input()
t =input()
res=""
if n>=m:
for i in range(n):
if (s[i:i+m]==t):
res+="1"
else:
res+="0"
for i in range(q):
c0,c1 = map(int, input().split())
if (m>n) or (c1-c0+1<m):
print (0)
else :
print (res[c0-1:c1-... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | 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
for i in range(n-1,-1,-1): a[i]+=a[i+1];
for k in range(q):
l, r = map(int, input().split())
l = l-1
r = r-m
res = a[l]-a[r+1] if l<=r else 0
print(res) | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.io.*;
import java.util.StringTokenizer;
public class Solution {
public static void main(String[] args) throws IOException {
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
int m = in.nextInt();
int... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | #import io, os
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from sys import stdout
print = stdout.write
## reference from pajendoc
n, m, q = map(int, input().split())
s = str(input())
t = str(input())
ans = []
i = j = 0
while True:
x = s.find(t, i)
if x != -1:
for _ in range(x-i+1):
ans.appen... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | import sys, math
from sys import stdin, stdout
rem = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 6)
take = lambda: map(int, raw_input().split())
from bisect import bisect_right,bisect_left
n,m,q=take()
arr=list(raw_input())
new=list(raw_input())
left=[-1]
right=[-1]
for i in range(n-m+1):
#print arr[i:i+m]
if arr[... | PYTHON |
1016_B. Segment Occurrences | 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... | 2 | 8 | n,m,q=map(int,input().split())
s=input()
t=input()
x=0
dp1=[0 for i in range(n)]
while x<n:
if s[x-m+1:x+1]==t:
dp1[x]=1
else:
dp1[x]=0
x+=1
dp=[]
for i in range(n):
acum=0
dp.append([])
for j in range(i):
dp[-1].append(0)
for j in range(i,n):
if dp1[j]!=0 and... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.util.Scanner;
public class Codeforces {
public static String slovo(String s, int pos, int dl) {
String rt = "";
for (int i = pos; i < pos + dl; i++) {
rt += s.charAt(i);
}
return rt;
}
public static void main(String[] args) {
Scanner ... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
char str[maxn], s[maxn];
struct node {
char ch;
int val;
node() {}
node(char _ch, int _val) : ch(_ch), val(_val) {}
};
node stk[maxn];
int top;
int f[maxn];
int tr[maxn];
int len1, len2;
void update(int x, int v) {
while (x <= len1) {
... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.io.IOException;
import java.io.InputStream;
public class B1016 {
public static void main(String[] args) throws IOException {
InputReader reader = new InputReader(System.in);
int N = reader.readInt();
int M = reader.readInt();
int Q = reader.readInt();
String S =... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005, MAXM = 1005;
string T, P, tt;
int Next[MAXM], N, M, C;
void MakeNext(int M) {
int i = 0, j = -1;
Next[i] = -1;
while (i < M) {
if (j == -1 || P[i] == P[j])
Next[++i] = ++j;
else
j = Next[j];
}
}
int KMP(int pos, int N, int ... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 | 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... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, q;
cin >> n >> m >> q;
string s, t;
cin >> s >> t;
int ans[1000003] = {0};
for (int i = 0; i < n; i++) {
if (s.substr(i, m) == t) {
ans[i] = 1;
}
}
while (q--) {
int l, r, cnt = 0;
cin >> l >> r;
if (r - l + 1... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 | //6000 KB memory
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
public class Main //main class
{
static class FastReader
{
BufferedReader br;
StringTokenizer s... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
string a;
string b;
int ans[1000 + 7];
int main() {
int m, n, q;
cin >> m >> n >> q;
cin >> a >> b;
int tmp = 0;
for (int i = 0; i < m; i++) {
if (a[i] == b[0]) {
int cnt = 0;
for (int j = 0; j < n; j++) {
if (a[i + j] == b[j])
cn... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class B {
public static void main(String[] args) throws Exception {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
// Scanner scan = new Scanner(System.in);
PrintWriter out = new P... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | from sys import stdin
n,m,q = [int(x) for x in stdin.readline().rstrip().split()]
s=stdin.readline().rstrip().split()[0]
t=stdin.readline().rstrip().split()[0]
temp=[]
for j in range (0, n-m+1):
if s[j:j+m]==t:
temp.append(1)
else:
temp.append(0)
for i in range(q):
query=[int(x) for x in stdin.readline... | PYTHON |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.io.*;
import java.util.*;
public class CF1016B {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Inte... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | n,m,q = [int(x) for x in input().split()]
s = input()
t = input()
#precalculate all possible matches
cnt_lst = [0]
for i in range(len(s)):
val = 1 if s.startswith(t,i) else 0
cnt_lst.append(cnt_lst[-1] + val)
#print(cnt_lst)
for i in range(q):
l,r = [int(x) for x in input().split()]
x,y = l-1, r - len... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | #include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
template <class T1, class T2>
inline void checkmin(T1 &x, T2 y) {
if (x > y) x = y;
}
template <class T1, class T2>
inline void checkmax(T1 &x, T2 y) {
if (x < y) x = y;
}
template <class T1>
inline void sort(T1 &arr) {
sort(... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int MaxN = 100005;
int BIT[MaxN];
void update(int pos) {
int i, j, p, q;
for (i = pos; i < MaxN; i += i & (-i)) {
BIT[i] += 1;
}
}
int query(int pos) {
int i, j, p = 0, q;
for (i = pos; i > 0; i -= i & (-i)) {
p += BIT[i];
}
return p;
}
int main(... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
char s[2000], t[2000];
int f[2000];
int main() {
int n, m, q;
scanf("%d%d%d", &n, &m, &q);
scanf("%s", s + 1);
scanf("%s", t + 1);
for (int i = 1; i <= n - m + 1; i++) {
int flag = 1;
for (int j = 1; j <= m; j++)
if (s[i + j - 1] != t[j]) {
f... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 | import sys
range = xrange
input = raw_input
n,m,q = [int(x) for x in input().split()]
s = input()
t = input()
is_start = [False]*n
for i in range(n):
j = 0
while j<m and i+j<n and s[i+j]==t[j]:
j+=1
if j==m:
is_start[i]=True
A = [0]
for val in is_start:
if val:
A.append(A[-... | PYTHON |
1016_B. Segment Occurrences | 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... | 2 | 8 | 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.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
public c... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | 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,raw_input().split())
if ... | PYTHON |
1016_B. Segment Occurrences | 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... | 2 | 8 | n,m,q=map(int,input().split())
s=input()
s1=input()
st=[]
en=[]
l=[]
for i in range(n):
st.append(0)
en.append(0)
for i in range(n):
if s[i:i+len(s1)] ==s1:
l.append(1)
st[i]=1
en[i+len(s1)-1]=1
else:
l.append(0)
sums=0
sume=0
sa=[]
se=[]
a=[]
for i in range(n):
sums=sums+st[i]
sume=sume+en... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | [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]
for i in range(q):
[l,r]=input().split()
l=int(l)
r=int(r)
if (r - l + 1 < m):
print(0)
... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 |
def mi():
return map(int, input().split())
n,m,q = mi()
s = list(input())
t = list(input())
pre1 = [0]*n
pre2 = [0]*n
if n>=m:
for i in range(n-m+1):
if (s[i:i+m]==t):
pre1[i+m-1] = 1
pre2[i] = 1
for i in range(1,n):
pre1[i]+=pre1[i-1]
pre2[i]+=pre2[i-1]
pre1.insert(0,0)
pre2.insert(0,0)
while q:
q-... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | import sys
def get_array(): return list(map(int, sys.stdin.readline().split()))
def get_ints(): return map(int, sys.stdin.readline().split())
def input(): return sys.stdin.readline().strip('\n')
n , m , q = get_ints()
s = input()
p = input()
ans = []
i = 0
count = 0
while True:
si = s.find(p,i)
if si != -1:
... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | from collections import Counter
def main():
n, m, q = [int(c) for c in input().split()]
s = input()
t = input()
ok = []
pr = [0]
for i in range(0, n):
ok.append(1 if t == s[i:i+m] else 0)
pr.append(pr[-1] + ok[-1])
# print('[' + ', '.join(list(s)) + ']')
# print(ok)
# ... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | def main():
n, m, q = map(int, input().split())
s, t = input(), input()
start, ps = [0] * n, [0] * (n+1)
for i in range(n):
curr, left = 0, i
while left < n and s[left] == t[curr]:
curr += 1
left += 1
if curr == m:
start[i] = 1
... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | R=lambda:map(int,input().split())
n,m,q=R()
s,t=input(),input()
a=[0]
b=0
for i in range(n):
if s[i:i+m]==t:b+=1
a+=[b]
for _ in[0]*q:l,r=R();print(a[max(l-1,r-m+1)]-a[l-1]) | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | def mmhaxor(n,m,q,s,t):
a = [0]*(10000)
for i in range(n):
a[i+2] = a[i+1]+(s[i:i+m]==t)
for i in range(q):
ans = 0
l,r = map(int,input().split())
print(a[max(r-m+2,l)]-a[l])
n,m,q = map(int,input().split())
s =input()
t =input()
mmhaxor(n,m,q,s,t) | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | import sys
n,m,q = map(int,raw_input().split())
s = list(raw_input())
t = list(raw_input())
if n<m:
for i in range(q):
print 0
sys.exit()
arr = [0 for x in range(n+1)]
for i in range(n-m+1):
if s[i:i+m]==t:
arr[i+1] = 1
arr[i+1] += arr[i]
for i in range(n-m+1,n):
arr[i+1] += arr[i]
for i in range(q... | PYTHON |
1016_B. Segment Occurrences | 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... | 2 | 8 | n, m, q = map(int, input().split())
s = input()
t = input()
dp = [[0 for i in range(n)] for i in range(n)]
for left in range(n):
for right in range(left + m - 1, n):
if s[right - m + 1:right+ 1] == t:
dp[left][right] = dp[left][right - 1] + 1
else:
... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.util.*;
import java.util.regex.*;
import java.io.*;
public class Codeforces{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// BufferedReader br = new BufferedReader(new FileReader(new File("D:\\Shivang\\Java... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.io.*;
import java.util.*;
/**
* @author baito
*/
@SuppressWarnings("unchecked")
public class Main
{
static StringBuilder sb = new StringBuilder();
static FastScanner sc = new FastScanner(System.in);
static int INF = 123456789;
static int MINF = -123456789;
static long LINF = 123456789... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | n, m, q = map(int, input().split())
s = input()
t = input()
gas = ['LOL']
otv = []
c = m - 2
for i in range(n):
if s[i:i+m] == t:
gas.append(1)
else:
gas.append(0)
for i in range(q):
l, r = map(int, input().split())
if r - m >= 0:
otv.append(str(sum(gas[l:r - c])))
else:
... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | n, m, q = map(int, input().split())
s = input()
t = input()
pr = [0] * (1000 + 7)
ok = [0] * (1000 + 7)
pr[0] = 0
for i in range(n - m + 1):
fl = 1
for j in range(m):
if(s[i+j] != t[j]):
fl = 0
ok[i] = fl
pr[i+1] = pr[i] + ok[i]
for i in range(max(0, n - m + 1), n):
pr[i+1] = p... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | Input = lambda: map(int, input().split())
n, m, q = Input()
s = input()
t = input()
pre = [ 0 for i in range(n + 5)]
for i in range(0, n - m + 1):
if s[i:i+m] == t:
pre[i + 1] = 1
for i in range(1, n + 3):
pre[i] += pre[i - 1]
for i in range(q):
l, r = Input()
if r - l + 1 < m:
print(... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.util.Scanner;
public class SegmentOccurrence {
static class Query {
int l;
int r;
public Query(int l, int r) {
this.l = l;
this.r = r;
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n ... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n, m, l, r, q, nr;
string s;
string t;
cin >> n >> m >> q;
cin >> s >> t;
int cnt[1001] = {0};
for (int i = 0; i <= n - m; i++) {
if (s.substr(i, m) == t) {
cnt[i] = 1;
}
}
l = 0;
r = 0;
for (i = 1; i <= q; i++) {
... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 | import bisect
n,m,q=map(int,input().split())
s=input()
t=input()
def find_substring(substring, string):
indices = []
index = -1 # Begin at -1 so
while True:
index = string.find(substring, index + 1)
if index == -1:
break
indices.append(index+1)
return indices
... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | #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; ... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 | #include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long MAXN = 1e3 + 10;
long long n, m, q;
string a, b;
long long pref[MAXN];
inline void precalc() {
for (long long i = 0; i < n - m + 1; ++i) {
bool flag = true;
for (long long j = i; j < i + m; ++j) {
if (a[j] != b[j - ... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 | a1 = list(map(int, input().split(' ')[:3]))
bigString = input()
littleString = input()
all = 0
left = [0]*len(bigString)
right = [0]*len(bigString)
leftCount = 0
rightCount = 0
for i in range(len(bigString)):
left[i] = leftCount
if bigString.find(littleString,i,i + len(littleString)) != -1:
leftCount +=... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class SO1016Bv2 {
public static void main(String[] args) throws IOException {
BufferedReader inputs = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer th... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.util.*;
public class CodeforcesEdu48 {
public static Scanner scn = new Scanner (System.in);
public static void main(String[] args) {
// Q1();
// Q2();
Q2n();
}
private static void Q2n() {
int n = scn.nextInt();
int m = scn.nextInt();
int qn = scn.nextInt();
String s = scn.next();
String t... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
void add_self(int& a, int b) {
a += b;
if (a >= (int)1e9 + 7) a -= (int)1e9 + 7;
}
void solve() {
int n, m, q;
cin >> n >> m >> q;
string s, t;
cin >> s >> t;
vector<int> a(n + 1, 0);
int cnt = 0;
for (int i = 0; i <= n - m; i++) {
bool ok = true;
... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args)
{
FastReader reader = new FastReader();
PrintWriter writer = new PrintWriter(System.out);
int n = reader.nextInt();
int m = reader.nextInt();
int q = reader.nextInt();
char[] s = reader.nextLine().toCharArr... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | def count_overlapping_substrings(haystack, needle):
count = 0
i = -1
while True:
i = haystack.find(needle, i + 1)
if i == -1:
return count
left.append(i)
right.append(i + len(needle) - 1)
count += 1
def bin_search(lst, x):
lower_bound = 0
upper_b... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | from sys import stdin
from math import *
line = stdin.readline().rstrip().split()
n = int(line[0])
m = int(line[1])
q = int(line[2])
s = stdin.readline().rstrip().split()[0]
t = stdin.readline().rstrip().split()[0]
bools = [0] * (n - m + 1 + 1)
accum = 0
for i in range(n - m, -1, -1):
if s[i:i+m] == t:
... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int mxn = 1e3 + 5, seed = 131, seed2 = 31, MOD = 1e9 + 9;
int n, m, q;
string s, t;
long long p[mxn], pp[mxn], a[mxn], aa[mxn], b[mxn], bb[mxn];
inline long long strHash(int l, int r) {
return (long long)((1LL * a[r] - 1LL * a[l - 1] * p[r - l + 1] % MOD) + MOD) %
... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int q = sc.nextInt();
String s = sc.next();
Stri... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | import sys
input = sys.stdin.readline
class BIT():
def __init__(self, n):
self.size = n
self.bit = [0] * (n + 1)
def _sum(self, i):
s = 0
while i > 0:
s += self.bit[i]
i -= i & -i
return s
def add(self, i, val):
i += 1
while... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int match[1009];
int prefix[1009];
string s, t;
bool isMatch(int a) {
for (int i = 0; i < t.size(); i++) {
if (i + a >= s.size() || s[i + a] != t[i]) {
return false;
}
}
return true;
}
int main() {
ios_base::sync_with_stdio(0);
int n, m;
cin >> n >... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 | 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... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | #
import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)
def getIntList():
return list(map(int, input().split()))
try :
#raise ModuleNotFoundError
import numpy
def dprint(*args, **kwargs):
print(*args, **kwargs, file=sys.stderr)
dprint('debug mode')
except ... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | 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]) | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | # https://codeforces.com/contest/1016/problem/B
n , m , q=map(int,input().split())
goals = ''
s , t = input() , input()
for _ in range(n - m + 1):
if (s[_:_ + m] == t):goals += '1'
else:goals += '0'
for _ in range(q):
arguments = input().split()
l = int(arguments[0])
r = int(arguments[1])
if r... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | N, M, Q = map(int, raw_input().split())
s = raw_input()[:N]
t = raw_input()[:M]
psum = [0 for _ in range(len(s) + 1)]
for i in range(len(s)):
psum[i+1] = psum[i]
if t == s[i:i+len(t)]:
psum[i+1] += 1
for q in range(Q):
a, b = map(int, raw_input().split())
a -= 1
b -= len(t) - 1
b = ma... | PYTHON |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.io.*;
import java.util.*;
public class CF_segmentoccurences {
public static void main (String [] args) throws IOException {
//PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
//Scanner sc = new Scanner(System.in);//new File("input.txt"));
BufferedReader f =... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | n, m, q = map(int, input().split())
s = input()
t = input()
a=[]
b=[]
c=[0]*n
for i in range(n):
if s[i: i+m]==t:
b.append([i, i+m])
x=0
y=0
for i in range(n):
c[i]=y
if x<len(b) and i == b[x][0]:
x+=1
y+=1
x=0
y=0
d=[0]*n
for i in range(n):
if x<len(b) and i+1 == b[x][1]:
... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
sc.nextInt();
sc.nextInt();
int q = sc.nextInt();
String s = sc.next();
String t = sc... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, q, t = 0;
string a, b, s = "";
cin >> n >> m >> q >> a >> b;
vector<pair<int, int> > v;
while (t + b.size() - 1 < a.size()) {
if (a.substr(t, b.size()) == b) {
v.push_bac... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
string s, t;
int ans[100009];
int lps[100009];
int main() {
int n, m, q;
cin >> n >> m >> q;
cin >> s >> t;
int sz = t.size();
int sz1 = s.size();
for (int i = 1; i <= (sz1 + 1 - sz); i++) {
int flag = 0;
string sb = s.substr(i - 1, sz);
if (sb == t)... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 | n,m,q=map(int,input().split())
s=input()
t=input()
st=[0]*n
en=[0]*n
for i in range(n):
if(s[i:i+m]==t):
st[i]=1
en[i+m-1]=1
if(i>0):
st[i]+=st[i-1]
en[i]+=en[i-1]
st.insert(0,0)
for i in range(q):
l,r=map(int,input().split())
l-=1
r-=1
print(max(0,en[r]-st[l]))
| PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.util.*;
import java.io.*;
public class B48 {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int n = sc.nextInt(); int m = sc.nextInt(); int q = sc.nextInt();
String s = sc.... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | import sys
def solve(ist):
_ = ist.next_int()
_ = ist.next_int()
q = ist.next_int()
s = ist.next()
t = ist.next()
counts = [0 for _ in xrange(len(s) + 1)]
for i in xrange(1, len(s) + 1):
counts[i] = counts[i - 1]
if s[i - 1: i - 1 + len(t)] == t:
counts[i] += 1... | PYTHON |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigDecimal;
public class ER48B {
public static void main (String[] args) throws java.lang.Exception {
InputReader in = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int n = in.nextInt(), m ... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | def substr(str, start, length):
return str[start : (length + start)]
def main():
n, m, q = map(int, input().split())
s = input()
t = input()
a = [0] * n
for i in range(n - m + 1):
if substr(s, i, m) == t:
a[i] = 1
ans = []
for i in range(q):
l, r = map(int,... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 |
import java.util.ArrayList;
import java.util.Scanner;
// http://codeforces.com/contest/1016/problem/B
public class SegmantOccur {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int lenS = in.nextInt();
int lenT = in.nextInt();
int q = in.nextInt();
String strS ... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | a,b,n = map(int,input().split())
s = input()
t = input()
pre = [0]*100860
def pre_cnt(s1,s2):
for i in range(0,len(s1)-len(s2)+1):
if s1[i:i+len(s2)]==s2:
pre[i+1]=pre[i]+1
else: pre[i+1] = pre[i]
pre_cnt(s,t)
while n!=0:
n-=1
a,b = map(int,input().split())
ans = pre[b-len(t)... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.util.Scanner;
public class B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int[] pos = new int[n+2];
int q = sc.nextInt();
String s = sc.nextLine();
s = sc.nextLine();
... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
public class SegmentOccurrences {
static String P, S;
static Scanner scanner = new Scanner(System.in);
static int n, m, q;
static int a, b, length;
public static void main(String[] args) {
n = scanner.nextInt... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, q, i, j, l, r, a[5000];
string s, t;
cin >> n >> m >> q;
cin >> s >> t;
if (m > n) goto label;
if (s.compare(0, m, t) == 0) {
a[0] = 1;
} else
a[0] = 0;
for (j = 1; j <= n - m + 1; j++) {
if (s.compare(j, m, t) == 0) ... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ThreadLocalRandom;
public class Main {
final static int c = 1000000009;
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
int n = console.nextInt(), m = console.nextInt(), q = console.nextInt();
conso... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
public class B {
static int N,M,Q;
public static void main(String[] args) {
JS in = new JS();
PrintWriter out = new PrintWriter(S... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int max(int a, int b) { return (a > b) ? a : b; }
int min(int a, int b) { return (a < b) ? a : b; }
int main() {
int n, m, k;
cin >> n >> m >> k;
string s, t;
cin >> s;
cin >> t;
unordered_map<char, int> umap;
vector<int> skips;
for (int i = 0; i < t.size();... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 | 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 Test {
static class BIT {
private int[] array;
private int total;
public BIT(int[] ar) {
this.total = ar.length;
int i = 1... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | import sys
def mapi(): return map(int,input().split())
def maps(): return map(str,input().split())
#--------------------------------------------------
n,m,q = mapi()
s = input().strip()
t = input().strip()
i = 0
j = m
mp = {}
pf = [0]
for i in range(n-m+1):
if s[i:i+m]==t:
pf.append(pf[-1]+1)
else:
... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | n,m,q=map(int,input().split())
s=input()
t=input()
tt=[0]*1111
for i in range(n-m+1):
j=0
while j<m and s[i+j]==t[j]: j+=1
if j>=m: tt[i+1]=1
for i in range(1,n+1): tt[i]+=tt[i-1]
for i in range(q):
a,b=map(int,input().split())
if b-a+1<m:
print(0)
continue
print(tt[b-m+1]-tt[a-1... | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | 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... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | n,m,q=map(int,input().split())
s=input()
t=input()
ans=[0]*n
for i in range(n-m+1):
if s[i:i+m]==t:
ans[i]=1
# print(ans)
for i in range(q):
x,y=map(int,input().split())
if y-x+1<m:
print(0)
else:
print(sum(ans[x-1:y-m+1])) | PYTHON3 |
1016_B. Segment Occurrences | 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... | 2 | 8 | def start(s1,s2):
l=[0]*len(s1)
for i in range(len(s1)):
if(s1[i:i+len(s2)]==s2):
l[i]=1
return l
def c(a,b,l,m):
r,n=0,b-a+1
if(b-a+1<m):
return 0
else:
return sum(l[a:b-m+2])
n,m,q=map(int,raw_input().split())
s1=raw_input()
s2=raw_input()
l=start(s1,s2)
#pr... | PYTHON |
1016_B. Segment Occurrences | 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... | 2 | 8 | import java.util.*;
import java.math.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
//--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------
public class a{
static int[] count,... | JAVA |
1016_B. Segment Occurrences | 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... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const long long mod[] = {(long long)1e9 + 7, (long long)1e9 + 9,
(long long)1e9 + 21, (long long)1e9 + 33};
const int maxn = 2e3 + 5;
const int Nmod = 3;
string a, b;
int i, j, n, m, q;
long long Pow[Nmod][maxn];
static long long Hash[Nmod][maxn], H... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int main() {
ios_base::sync_with_stdio(false);
int n, m, q, l, r, tlen, cnt;
char s[N], t[N];
bool match[N] = {0};
cin >> n >> m >> q >> s >> t;
tlen = strlen(t);
for (int i = 0; s[i]; ++i) {
match[i] = !strncmp(s + i, t, tlen);
}... | CPP |
1016_B. Segment Occurrences | 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... | 2 | 8 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new Input... | JAVA |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.