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
#include <bits/stdc++.h> using namespace std; char a[1005], b[1005]; int sum[1005]; int main() { ios::sync_with_stdio(false); int n, m, t; cin >> n >> m >> t; cin >> a + 1 >> b + 1; for (int i = m; i <= n; i++) { for (int j = 1; j <= m; j++) { if (a[i - m + j] != b[j]) break; if (j == m) sum[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
#include <bits/stdc++.h> using namespace std; long long pw[(int)1e6 + 5]; long long base = 1331; long long Hash[(int)1e6 + 5]; void preCal() { pw[0] = 1; for (int i = 1; i < (int)1e6 + 5; i++) pw[i] = pw[i - 1] * base; } void setHash(string s) { Hash[0] = 0; for (int i = 1; i < s.size(); i++) Hash[i] = Hash[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 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.StringTokenizer; public class B { public static void main(String[] args) { InputStream inputStream = System.in; OutputS...
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::sync_with_stdio(0); cin.tie(0); int n, m, q; string s, t; cin >> n >> m >> q >> s >> t; vector<int> ans; for (int i = 0; i < n; i++) { bool flag = 1; for (int j = 0; j < m; j++) { if (t[j] != s[j + i]) { flag = 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> using namespace std; char str[1011]; char ptr[1011]; int Next[1011]; int plen, slen; int n, m, q, x, y; inline int in() { int f = 1, ans, ch; while ((ch = getchar()) < '0' || ch > '9') if ('-' == ch) { ch = getchar(), f = -1; break; } ans = ch - '0'; while ((ch = get...
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.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public ...
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 = str(input()) t = str(input()) ans = list() if n >= m: buf = "" for i in range(0, m-1): buf += s[i] for i in range(m-1, n): buf += s[i] ok = 1 for j in range(m): ok &= buf[i - m + 1 + j] == t[j] ans.append(ok) while 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> using namespace std; int main() { int n, m, q; string a, b; cin >> n >> m >> q >> a >> b; vector<int> v(n); for (int i = 0; i < n; i++) { bool good = true; if (i) v[i] = v[i - 1]; for (int j = 0; j < m; j++) { if (a[i + j] != b[j]) { good = false; bre...
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 a[1005], b[1005], c[1005]; int p[1005]; int n, m, q; void pipei() { int l, r, j = 0; scanf("%d%d", &l, &r); int lb = m; int la = r - l + 1; for (int i = l; i <= r; i++) c[i - l + 1] = a[i - 1]; for (int i = 2; i <= lb; i++) { while (j > 0 && b[i] != 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
import java.util.Scanner; public class SegmentOcc { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(),m=sc.nextInt(),q=sc.nextInt(); String s=new String(sc.next()); String t=new String(sc.next()); int a[]=new int[1000]; ...
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 n, m, q, l, r; char s[1005], t[1005]; int sum[1005]; int flag[1005]; int main() { scanf("%d%d%d", &n, &m, &q); scanf("%s", &s); scanf("%s", &t); sum[0] = 0; for (int i = 0; i < n - m + 1; i++) { int now = 1; for (int j = 0; j < m; j++) { if (s[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
n,m,k=map(int,input().split()) a=list(input()) b=list(input()) l =[] j=0 while j<n-m+1: if j+m <= n: if a[j:j+m]==b: l.append(j) else: break j += 1 for i in range(k): x,y = map(int,input().split()) c=0 x-=1 y-=1 for i in range(len(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
#include <bits/stdc++.h> using namespace std; long long n, m, q, l, r; long long arr[10000]; char s[10000], t[10000]; int main() { cin >> n >> m >> q; cin >> s + 1 >> t + 1; for (long long i = 1; i <= n - m + 1; i++) { int acc = 1; for (int j = 1; j <= m; j++) if (acc == 1 && s[i + j - 1] != t[j]) a...
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(' '))) text = list(input()) patt = list(input()) cnt=[0 for i in range(n)] if(m>n): for i in range(q): l,r=(map(int,input().split(' '))) print(0) else: for i in range(n): if(i+m>n): break if(text[i:i+m]==patt): cnt[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
import sys import io stream_enable = 0 inpstream = """ 15 2 3 abacabadabacaba ba 1 15 3 4 2 14 """ if stream_enable: sys.stdin = io.StringIO(inpstream) input() def inpmap(): return list(map(int, input().split())) n, m, q = inpmap() a = input() b = input() s = [0] * n s[0] = int(a.startswith(b)) for i i...
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 n, m, q; string s, t; int st[1010], ed[1010]; int main() { ios_base::sync_with_stdio(false); cin >> n >> m >> q; cin >> s >> t; for (int i = 0; i < n - m + 1; i++) { bool ok = true; for (int j = 0; j < m; j++) { if (t[j] != s[i + j]) { ok =...
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 = [int(x) for x in input().split()] S = input() #length N T = input() #length M A = [] pref = [] for i in range(N): A.append(0) pref.append(0) for i in range(N): if S[i:i+M] == T: A[i] = 1 if i > 0: pref[i] = pref[i-1] + A[i] else: pref[i] = A[i] for i in range(Q): l,r = [int(x) for x in i...
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
""" a=mt.floor(n/2)+mt.floor(n/3)+mt.floor(n/4) if a>n: print(int(a)) else: print(n) 15 2 3 abacabadabacaba ba 1 15 3 4 2 14 """ n,m,k=map(int,input().split()) a=list(input()) b=list(input()) l =[] j=0 while j<n-m+1: if j+m <= n: if a[j:j+m]==b: l.ap...
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; public class Segment_Occurrences { static boolean dp[]; static int tt[]; public static void main(String[] args) { Scanner sc = new Scanner (System.in); int n=sc.nextInt(),m=sc.nextInt(),q=sc.nextInt(); String s = sc.next(),t=sc.next(); dp = new boolean [n+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
try: while True: n, m, q = list(map(int, input().split())) str1 = input() str2 = input() cnt = [0] * (n+1) for l in range(n): #print(str1[l:l+m]) if str1[l:min(l+m, n)] == str2: cnt[l+1] = cnt[l] + 1 else: c...
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> const long long N = 1e6 + 10; const long long mod = 998244353; using namespace std; long long w[1111]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m, q; cin >> n >> m >> q; string a, b; cin >> a >> b; for (long long i = 0; i < n - m + 1; 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
#include <bits/stdc++.h> int a[1000]; using namespace std; int main() { int n, m, q, l, r, i, x; scanf("%d %d %d", &n, &m, &q); string s1, t; cin >> s1 >> t; for (i = 0; i <= n - m; i++) { if (s1.substr(i, m) == t) a[i] = 1; } while (q--) { x = 0; scanf("%d %d", &l, &r); for (i = l - 1; 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
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=[[0 for i in range(n)] for j in range(n)] for i in range(n): acum=0 for j in range(i,n): if dp1[j]!=0 and j-m+1>=i: acum...
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 long long INF = (1LL << 45LL); const long long MAXLL = 9223372036854775807LL; const unsigned long long MAXULL = 18446744073709551615LLU; const long long MOD = 1000000007; const long double DELTA = 0.000000001L; inline long long fmm(long long a, long long b, long long ...
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 long long N = 2e5 + 5, MOD = 1000000007; long long n, m, q; string s, t; vector<long long> v; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m >> q >> s >> t; for (long long i = 0; i < n; i++) { if ((m + 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
#!/usr/bin/python2 # -*- coding: utf-8 -*- import sys def rl(proc=None): if proc is not None: return proc(sys.stdin.readline()) else: return sys.stdin.readline().rstrip() def srl(proc=None): if proc is not None: return map(proc, rl().split()) else: return rl().split() ...
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
from sys import stdin,stdout from bisect import bisect_left def main(): n,m,q=map(int,stdin.readline().split( )) s=stdin.readline(); t=stdin.readline(); start=[];end=[] for i in range(n-m+1): j=0 while j<m and s[i+j]==t[j]: j+=1 if j==m: start.append(i) end.append(i+j-1) len_start=len(start) 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
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 = 1234567890; static long LINF = 123456789123456789L; static long MINF...
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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class quesries { public static void main(String[] args) { // TODO Auto-generated method stub FastReader s=new FastReader(); int n=s.nextInt(); int m=s.nextInt(); int q=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
n, m, q = map(int, input().split()) s = input() t = input() pat = [0] * n i = 0 c = 0 while True: f = s[i:].find(t) if f == -1: for j in range(i, n): pat[j] = c break g = i + f for j in range(i, g): pat[j] = c c += 1 pat[g] = c i = g + 1 pat = [0] + pat f...
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 n, m, q; int nxt[100001]; char s[100001], t[100001]; int temp[100001]; int l, r; bool check(int u) { for (int i = 0; i < m; ++i) { if (s[u + i] != t[i]) return 0; } return 1; } void pre_do() { for (int i = 1; i <= n - m + 1; i++) { temp[i] += check(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
#include <bits/stdc++.h> using namespace std; const int maxx = 1000004; struct XXX { long long x, y; } xx[maxx]; bool my(XXX a, XXX b) { return a.x < b.x; } bool mt(long long a, long long b) { return a > b; } long long a[maxx], b[maxx]; long long read() { long long k; scanf("%lld", &k); return k; } long long 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.Objects; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelpe...
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.*; import java.io.*; public class Solution { static Scanner in =new Scanner(System.in); static final Random random=new Random(); static int mod=1000_000_007; public static void main(String[] args) { //int tt=in.nextInt(); // outer:while(tt-->0) { int n=in.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; const int N = 1021; int n, m, q, ans[N]; string s, t; int main() { cin >> n >> m >> q; cin >> s >> t; for (int i = 0; i + m <= n; i++) if (s.substr(i, m) == t) ans[i + 1]++; for (int i = 2; i <= n; i++) ans[i] += ans[i - 1]; while (q--) { int a, b; cin...
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; int n, m, q, a[2010], sum[2010]; string s, t; vector<pair<int, int> > v; int main() { cin >> n >> m >> q; cin >> s; cin >> t; for (int i = 0; i < n && i + m - 1 < n; i++) { bool found = true; for (int j = 0; j < m && j + i < n; j++) { if (s[i + j] != 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
import sys def main(): n, m, q = map(int, input().strip().split()) s = input() t = input() pos = [] for i in range(len(s)): if i + len(t) <= len(s) and s[i:i+len(t)] == t: pos.append(1) else: pos.append(0) sum = [0] for i in range(len(pos)): ...
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; char s1[1005]; char s2[1005]; int ans[1005]; int main() { int n, m, q, r, l, len1, len2, an, count = 0; bool flag; scanf("%d %d %d", &n, &m, &q); scanf("%s", s1); scanf("%s", s2); len1 = strlen(s1); len2 = strlen(s2); for (int i = 0; i < len1 - len2 + 1; 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
n, m, q = map(int, input().split()) s = input() t = input() a = [0] * (1000 + 7) b = [0] * (1000 + 7) for i in range(n - m + 1): fl = 1 for j in range(m): if s[i + j] != t[j]: fl = 0 break b[i] = fl a[i + 1] = a[i] + b[i] for i in range(max(0, n - m + 1), n): a[i + ...
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 = list(map(int,input().split())) s = input() t = input() def check(i): if len(t) > len(s): return 0 for k in range(i,i+len(t)): if s[k] != t[k-i]: return 0 return 1 pref = [0] for i in range(len(s)-len(t)+1): pref.append(pref[-1]+check(i)) for i in range(len(s)-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 re import bisect def preprocess(s, t): starts = [] ends = [] l = len(t) for m in re.finditer('(?=%s)' % t, s): starts.append(m.start() + 1) ends.append(m.start() + l) # print(starts) # print(ends) return starts, ends def run(l, r, starts, ends): lpos = bisect....
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; int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long n, m, q; cin >> n >> m >> q; string s, t; cin >> s >> t; vector<long long> matchingId; for (long long i = 0; i <= n - m; i++) { string second = s.substr(i, m); if (second == 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() arr = [] for i in range(n - m + 1): if s[i:i + m] == t: arr.append(i) for i in range(q): l, r = map(int, input().split()) k = 0 for j in range(len(arr)): if arr[j] >= l - 1 and arr[j] + m - 1<= r - 1: k = k + 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
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, m, q; cin >> n >> m >> q; string s1, s2; cin >> s1 >> s2; long long int arr[n], d = 0; for (long long int i = 0; i <= n - m; i++) { string s3 = s1....
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
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
import re, bisect n, m, q = [int(v) for v in input().split()] s = input().strip() t = input().strip() starts = [m.start() for m in re.finditer('(?=%s)' % t, s)] for _ in range(q): l, r = [int(v) for v in input().split()] if r - l + 1 < len(t): print(0) else: print(bisect.bisect_right(star...
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
// 10-Feb-2021 import java.util.*; import java.io.*; public class B { static class FastReader { BufferedReader br; StringTokenizer st; private FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st ...
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 B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = Integer.parseInt(sc.next()); int m = Integer.parseInt(sc.next()); int q = Integer.parseInt(sc.next()); String s = sc.next(); String t = sc.next(); for (int i = 0; i < q; 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
# Python program for KMP Algorithm def KMPSearch(pat, txt): ans = [] M = len(pat) N = len(txt) # create lps[] that will hold the longest prefix suffix # values for pattern lps = [0]*M j = 0 # index for pat[] # Preprocess the pattern (calculate lps[] array) computeLPSArray(pat, M, lps) i = 0 # ind...
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.ArrayList; import java.util.Collections; public class B { private static char T[], P[]; private static int b[], n, m; private static ArrayList<Integer> subs; private static void kmpPreproces...
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() { vector<int> left, right; int n, m, s, l, r; string kata, q; cin >> n >> m >> s; cin >> kata >> q; size_t pos = kata.find(q, 0); while (pos != string::npos) { left.push_back(pos + 1); right.push_back(pos + m); pos = kata.find(q, pos + 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
n, m, q= map(int,input().split()) s,t = input(), input() ans = "" for i in range(n-m+1): if s[i:i+m] == t: ans += "1" else:ans += "0" for i in range(0,q): l, r = map(int,input().split()) if r-l+1 >= m: print(ans[l-1 : r-m+1].count("1")) else: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
#include <bits/stdc++.h> using namespace std; int a[10000]; int inds[10000]; int main() { int n, m, q; cin >> n >> m >> q; string str, target; cin >> str >> target; for (int i = 0; i <= (n - m); i++) { if (str[i] == target[0]) { string temp = str.substr(i, m); if (temp == target) a[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
n, m, q = [int(i) for i in input().split()] S = input() T = input() A = [[int(i) for i in input().split()] for j in range(q)] s = [] for i in range(len(S)): if S[i:i+len(T)] == T: s.append(1) else: s.append(0) csum = [0] for s_ in s: csum.append(csum[-1] + s_) for a, b in A: print(cs...
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
######### ## ## ## #### ##### ## # ## # ## # # # # # # # # # # # # # # # # # # # # # # # ### # # # # # # # # # # # # # ##### # # # # ### # # # # # # # # ##### # # # # # # # # # # # # # # # # # # #########...
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.io.FilterInputStream; import java.io.BufferedInputStream; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Jenish */ public class Ma...
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 urmi() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { long long n, m, q, i, c = 0, d = 0, e, f; cin >> n >> m >> q; string s, t; cin >> s >> t; map<long long, long long> m1; for (i = 0; i < n; i++) { if (s.compar...
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, raw_input().split()) s = raw_input() t = raw_input() positions = [] for i in xrange(len(s) - len(t) + 1): if t == s[i:i + len(t)]: positions.append(i) def bsearch(positions, x): if len(positions) == 0: return 0 l = 0 r = len(positions) while l + 1 != r: ...
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
#include <bits/stdc++.h> using namespace std; int pre[1005], p, n, m, t, l, r; char a[1005], b[1005]; int main() { cin >> n >> m >> t; cin >> (a + 1) >> b; for (int i = 1; i <= n - m + 1; i++) { p = 0; for (int j = 0; j < m; j++) { if (a[i + j] != b[j]) { p = 1; break; } } ...
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 str, sub; vector<long long int> v; int main() { long long int n, m, q, x, y; cin >> n >> m >> q; cin >> str >> sub; size_t pos = str.find(sub, 0); while (pos != string::npos) { v.push_back(pos); pos = str.find(sub, pos + 1); } while (q--) { ...
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() nex = -1 i = 0 ans = [0]*n while(i<n): if s[i] == t[0]: nex = -1 start = i i += 1 j = 1 flag = False while(i<n and j<m): if not flag: if s[i] == t[0]: nex = i ...
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)=input().split(' ') n=int(n) m=int(m) q=int(q) s=input() t=input() length=len(t) su=[0,] now=0 for i in range(len(s)-length+1): if s[i:i+length]==t: now+=1 su.append(now) #print(su) for i in range(q): (l,r)=input().split(' ') l=int(l) r=int(r)-length+1 if r>=l: #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
n, m, q = map(int, input().split()) s = input() t = input() if len(t) > len(s): for _ in range(q): print(0) else: pos = s.find(t) cnt = [0] while pos != -1: while len(cnt) <= pos: cnt.append(cnt[-1]) cnt.append(cnt[-1] + 1) pos = s.find(t, pos + 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 a[1005]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, q; cin >> n >> m >> q; string s, t; cin >> s >> t; for (int i = 0; i + m <= n; ++i) { if (s.substr(i, m) == t) { a[i + 1]++; } } for (int i = 1; i <= n; ++i) a[i] += a[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
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 k in range(q): l, r = map(int, input().split()) l = l-1 r = r-m res = sum(a[l: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
n,m,q = map(int,input().split()) a = input() b = input() c = [0] d = 0 for i in range(m-1,n): if (a[i-m+1:i+1] == b): d += 1 c.append(d) for i in range(q): x,y = map(int,input().split()) if (y-x+1) < m: print(0) else: print(max((c[y-m+1]-c[x-1]),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
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): k += 1 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
n, m, q = map(int, input().split()) s = input() t = input() ht = hash(t) hss = [hash(s[i : i + m]) for i in range(n - m + 1)] lhss = n - m + 1 for i in range(q): l, r = map(int, input().split()) c = 0 for j in range(l - 1, r): if j + m > r: continue if j < lhss and hss[j] == ht: ...
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 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 ...
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.util.Collections; import java.util.ArrayList; 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; ; 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]; ...
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> int a, b, c, i, j, ch, x, y, S[1004]; char s[1004], w[1004]; int main() { scanf("%d%d%d", &a, &b, &c); scanf("%s%s", s, w); for (i = 0; i + b - 1 < a; i++) { ch = 0; for (j = 0; j < b; j++) { if (s[i + j] == w[j]) ch++; } if (ch == b) { S[i + 1]++; } S[...
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.text.*; /** * * @author alanl */ public class Main{ static BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out...
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() arr = [0] * n for i in range(n - m + 1): arr[i] = arr[i-1] if s[i : i + m] == t: arr[i] += 1 # print(arr) for case in range(q): l, r = map(int, input().split()) l -= 1 r -= 1 # print(s[l:r+1]) # print(arr[]) if r - m + 1 < 0: print(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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class SegmentOccurences { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 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; char a[1000010]; char b[1000010]; int f[1000010]; int n, m, t; int main() { cin >> n >> m >> t; cin >> a + 1 >> b; for (int i = 1; i <= n - m + 1; i++) { bool mark = 1; for (int j = 0; j < m; j++) { if (a[i + j] != b[j]) { mark = 0; break...
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().strip().split()) s=input() t=input() le=len(t) l1=[0 for i in range(n+2)] count=0 for i in range(0,n-le+1): if (s[i:i+le]==t): l1[i+1]=-1 count=count+1 l2=[0 for i in range(n+2)] l2[1]=count for i in range(2,n+2): l2[i]=l2[i-1]+l1[i-1] for i in range(q): r1,r2=map(int,i...
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 main() { long long n, m, q; scanf("%lld", &n), scanf("%lld", &m), scanf("%lld", &q); string s, t; cin >> s >> t; long long cs[n + 10]; cs[0] = 0; memset(cs, 0, sizeof cs); for (long long i = 0; i < n; i++) { bool f = true; if (n < m) { cs[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 java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); int q = in.nextInt(); String s = in.next(); String t = in.next(); 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 bisect first = list(map(int, input().split())) a = input() b = input() n, m, q = first[0], first[1], first[2] starts = [] # preprocess string # brute force: determine each starting point for i in range(n - m + 1): if a[i:i + m] == b: starts.append(i + 1) for _ in range(q): endpoints = list(map(...
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 val[1005], rang[1005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s, t; int n, m, q; cin >> n >> m >> q; cin >> s >> t; for (int i = 0; i < s.size(); i++) { int cnt = 0; for (int j = 0; j < t.size(); j++) { if (i + j >= s.s...
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; vector<int> z_function(string s) { int n = (int)s.length(); vector<int> z(n); for (int i = 1, l = 0, r = 0; i < n; ++i) { if (i <= r) z[i] = min(r - i + 1, z[i - l]); while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i]; if (i + z[i] - 1 > r) { l = ...
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
from bisect import bisect_right as br from bisect import bisect_left as bl ar = map(int, raw_input().split()) s = raw_input() t = raw_input() lis = [] i = 0 while(1): i = s.find(t, i) if i == -1: break lis.append(i+1) i+=1 for i in range(0, ar[2]): a = map(int, raw_input().split()) e = br(lis, a[1]-ar[1]+1) s...
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 B { static FastReader sc=null; public static void main(String[] args) { sc=new FastReader(); PrintWriter out=new PrintWriter(System.out); int n=sc.nextInt(),m=sc.nextInt(),q=sc.nextInt(); char s[]=sc.next().toCharArray(),t[]=sc.next().toCharAr...
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() o="" for i in range(0,n-m+1): if s[i:i+m]==t: o+="1" else: o+="0" for i in range(0,q): l,r=map(int,input().split(" ")) if r-l+1>=m: print(o[l-1:r-m+1].count("1")) else: 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 preprocess(s, t): arr = [0 for i in s] for i in range(len(s)): for j in range(len(t)): if i + j >= len(s) or s[i + j] != t[j]: break else: arr[i] = 1 return arr def get_prefices(arr): prefices = [0 for i in arr] prefices[0] = arr[0] f...
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
#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> amijanina; for (int i = 0; i < s.size(); i++) { bool iloveuazrin = true; for (int j = 0; j < t.size(); j++) { if (s[i + j] != t[j]) { iloveuazrin = false;...
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; int n, m, q; string s, t; int a[1024]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m >> q; cin >> s >> t; for (int i = 0; i <= n - m; i++) { a[i] = 1; for (int j = 0; j < m; j++) { if (s[i + j] != t[j]) { a[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
import java.util.*; import java.lang.*; public class Solution { static Scanner in = new Scanner(System.in); public static void main(String []args){ int n = in.nextInt(); int m = in.nextInt(); int q = in.nextInt(); String a = in.next(); String b = in.next(); char arra[] = a.toCharArray(); char arrb[] =...
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 N = 1e3 + 5; int n, m, q, dp[N][N], p[N + N], used[N + N]; string s, t; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> q >> s >> t; string x = t + "#" + s; for (int i = 1; i < (int)x.size(); i++) { int j = p[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
#include <bits/stdc++.h> using namespace std; const long long MX = 1e3 + 100, INF = 1e17, INF2 = -1e18, D = 1e9 + 7; long long par[MX]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m, q; cin >> n >> m >> q; string s, t; cin >> s >> t; for (long long i = n - m; 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
n,m,q=map(int,raw_input().split()) a=raw_input();b=raw_input();k=len(b) pre=[0 for j in range(n)] pre2=[0 for j in range(n)] for i in range(n): if (i+k)<=n: if a[i:i+k]==b: pre[i]+=1 pre2[i+k-1]+=1 for i in range(1,n): pre[i]+=pre[i-1] for j in range(n-2,-1,-1): pre2[j]+=pre2...
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
from itertools import accumulate n,m,q = map(int,input().split()) a = input() b = input() acc = [0] + list(accumulate([ int(a[i:i+m] == b)for i in range(n-m+1)])) for i in range(q): x,y= map(int,input().split()) if n<m: print(0) else: print(max(0,acc[max(y-m+1,0)]-acc[min(x-1,n-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
#include <bits/stdc++.h> using namespace std; char s[1005], t[1005]; int n, m, q; int c[1005]; int main() { scanf("%d%d%d", &n, &m, &q); scanf("%s", s + 1); scanf("%s", t + 1); for (int i = 1; i <= n; i++) { c[i] = c[i - 1]; int d = 1; for (int j = 1; j <= m; j++) { if (s[i + j - 1] != t[j]) d...
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> const double PI = acos(-1.0); using namespace std; int setb(int n, int pos) { return n = n | (1 << pos); } int resb(int n, int pos) { return n = n & ~(1 << pos); } bool checkb(long long n, long long pos) { return (bool)(n & (1ll << pos)); } long long bigmod(long long b, long long p, long long m...
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; long long n, m, f[200000], d[200000], i, j, l, r, q, edd; string s, t; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> q; cin >> s >> t; for (i = 0; i < n; i++) { if (s[i] == t[0] && i + m <= n) { edd = 1; for...
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 = 1e6 + 7; const int M = 1e5 + 7; const long double pi = 3.1415926535897; int n, m, q, l, r, cnt[N]; string s, t; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> q; cin >> s; cin >> t; s = ' ' + s; t = ' ' + 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
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
#include <bits/stdc++.h> #pragma GCC optimize "Ofast" #pragma GCC optimize "unroll-loops" #pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native" char _; using namespace std; string a, b; int n, m, q, c, d; int PSA[3010]; int main() { cin.sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m...
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
lena, lenb, noq = [int(x) for x in input().split()] a = input() b = input() ''' for i in range(noq): s, e = [int(x)-1 for x in input().split()] curr = a[s:e+1] #print(curr) ans = sum(1 for _ in re.finditer('(?='+b+')', curr)) print(ans) ''' cnts = [0] * lena for i in range(lena): cnts[i] += a[i...
PYTHON3