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 | /*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
impor... | 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 CoinsAndQueries {
public static ArrayList<Integer>[] arr;
public static int moves=0;
static Scanner scan=new Scanner(System.in);
public static void main(String[] args) {
int n, m,q;
n=scan.nextInt();
m=scan.nextInt();
q=scan.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 | import java.io.*;
import java.util.*;
public class HelloWorld{
public static void main(String []args)throws IOException
{
//System.out.println("Hello World");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer(br.readLine());... | 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 math import ceil
#from sys import stdout
t = 1#int(input())
for test in range(1,t+1):
n,m,q = map(int, input().split())
s = input()
t = input()
indices = [0 for i in range(n)]
for i in range(n):
tmp = s.find(t, i)
if tmp==-1:
break
else:
indice... | 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 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())
print(max(0,acc[max(y-m+1,0)]-acc[max(0,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;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m, q, i, j;
cin >> n >> m >> q;
string a, b;
cin >> a >> b;
vector<long long> v(n + 1);
for (i = 0; i <= n - m; i++) {
string tmp = a.substr(i, m);
if (tmp == b) v[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.*;
import java.util.*;
public class CF1016_B {
public static void main(String[] args)throws Throwable {
MyScanner sc=new MyScanner();
PrintWriter pw=new PrintWriter(System.out);
int n=sc.nextInt();
int m=sc.nextInt();
int q=sc.nextInt();
char [] s=sc.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() {
ios_base::sync_with_stdio(false);
cin.tie(0);
;
long long int n, m, q;
cin >> n >> m >> q;
string s, t;
cin >> s >> t;
long long int l, r;
long long int cnt;
long long int ans[10005] = {0};
for (long long int 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>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n, m, q;
cin >> n >> m >> q;
int cnt[n + 1];
string s, s1;
cin >> s >> s1;
s = "1" + s;
int k = s.find(s1);
if (k == string::npos)
fill(cnt, cnt + n, 0);
else {
fill(cnt, cnt + k, 0);
cnt[k] = 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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, q;
cin >> n >> m >> q;
string s1, s2;
cin >> s1 >> s2;
vector<pair<int, int> > p;
int ans = 1;
for (int i = 0; i < n; i++) {
if (s1[i] == s2[0]) {
for (int k = 1; k < m && i + k < n; k++) {
if (s1[i + k] == s2[k]) ans++... | 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 | R=lambda:map(int,input().split())
n,m,q=R()
s,t=input(),input()
a=[0]*1005
for i in range(n):a[i+2]=a[i+1]+(s[i:i+m]==t)
for _ in[0]*q:l,r=R();print(a[max(l,r-m+2)]-a[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.io.*;
import java.util.*;
public class Main
{
static int KMPSearch(String pat, String txt)
{
int M = pat.length();
int N = txt.length();
int count = 0;
int lps[] = new int[M];
int j = 0;
computeLPSArray(pat,M,lps);
int i = 0;
while (i < 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 | n, m, q = map(int, input().split())
s = input()
t = input()
c = [0 for i in range(n+1)]
b = 0
for i in range(n-m+1):
#print (s[i:i+m])
if s[i:i+m] == t:
c[i+1] = 1
for i in range(1,n+1):
c[i] += c[i-1]
for i in range(q):
l, r = map(int, input().split())
if r-l+1 < m:
print (0)
else:
if l == 1:
print (c[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 | 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 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3;
char s[MAXN];
char t[MAXN];
int Begin[MAXN];
int main() {
int n, m, q;
int ans;
int i, j;
int l, r;
cin >> n >> m >> q;
cin >> s + 1;
cin >> t + 1;
for (i = 1; i + m - 1 <= n; i++) {
for (j = 1; j <= m; j++) {
if (s[i + j - 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 | def prefix_func(s):
slen, k = len(s), 0
p = [0]*slen
p[0] = 0
for i in range(1, slen):
while k>0 and s[k] != s[i]:
k = p[k-1]
if s[k] == s[i]:
k += 1
p[i] = k
return p
def kmp(s, p):
q, slen, plen = 0, len(s), len(p)
res = []
pi = prefix_... | 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,k=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
for tc in range(k):
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 | #include <bits/stdc++.h>
using namespace std;
int n, m, q;
int i, j;
char s[1005];
char t[1005];
int nx[1005];
int ck[1005];
int main() {
scanf("%d%d%d", &n, &m, &q);
scanf("%s", s + 1);
scanf("%s", t + 1);
for (i = 2; i <= m; i++) {
while (j && t[j + 1] != t[i]) j = nx[j];
if (t[j + 1] == t[i]) 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 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T> >;
const int maxn = (int)1e5 + 5;
const int inf = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;
const ld pi = acosl(-1.0);
const ld eps = 1e-9;
void 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.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
private static int[] arr;
private static int[] root;
private static int[] left;
private static int[] right;
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new ... | 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 Main
{
static ArrayList<Integer> occ;
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt(), m = scan.nextInt(),q = scan.nextInt();
char s[] = scan.next().toCharArray();
char t[] = scan.next().toC... | 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 MyClass {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int qn=sc.nextInt();
String s=sc.next();
String t=sc.next();
int q[][]=new int [qn][2... | 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
def main():
n, m , q = [ int(s) for s in stdin.readline().split(" ")]
s = stdin.readline().strip()
t = stdin.readline().strip()
queries = []
for line in range(0, q) :
queries.append( [ int(s) for s in stdin.readline().split(" ")])
acum = [0 for i in range... | 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=[]
b=[]
for i in range(3):
a.append(input())
for n in range(int(a[0].split(" ")[2])):
b.append(input())
c=0
# while c<len(b):
# l=int(b[c].split(" ")[0])
# r=int(b[c].split(" ")[1])
#
# d=a[1][l-1:r]
#
# size = []
# h=0
# while h < (len(d)-len(a[2])+1 ):
#
#
# size.append(d... | 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 itertools import accumulate
N, M, Q = [int(x) for x in input().split()]
S = input()
T = input()
L, R = [0]*Q, [0]*Q
for i in range(Q):
L[i], R[i] = [int(x) for x in input().split()]
is_substr = [0]*N
for i in range(N):
if S[i:i+M] == T:
is_substr[i] = 1
prefixes = [0]+list(accumulate(is_substr))
ou... | 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.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
public class r48p2{
static void update(int bit[], int val, int pos){
if(pos >= bit.length)
return;
bit[pos]+=val;
update(bit, val, pos+(pos&(-pos)));
... | 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 s1[(20ll + (long long int)1e3)];
char s2[(20ll + (long long int)1e3)];
long long int xds[(20ll + (long long int)1e3) << 2];
long long int eds[(20ll + (long long int)1e3) << 2];
long long int n, m;
long long int pushup(long long int cur) {
return xds[cur] = xds[cur <<... | 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, stdout
n,m,q=map(int,input().split())
s=input()
t=input()
x=0
dp1=[]
while x<n:
if s[x-m+1:x+1]==t:
dp1.append(1)
else:
dp1.append(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... | 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 | //package baobab;
import java.io.*;
import java.util.*;
public class B {
public static void main(String[] args) {
Solver solver = new Solver();
}
static class Solver {
IO io;
public Solver() {
this.io = new IO();
try {
solve();
... | 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 | R=lambda:map(int,raw_input().split())
n,m,q=R()
s=raw_input()
t=raw_input()
a=[0]*2000
for i in range(m,n+1):
a[i]=a[i-1]+(s[i-m:i]==t)
for _ in range(q):
l,r=R()
print max(0,a[r]-a[min(r,l+m-2)]) | 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>
#pragma warning(disable : 4996)
using namespace std;
int main() {
int n, m, q;
scanf("%d %d %d", &n, &m, &q);
string a, b;
cin >> a >> b;
int ps[1007] = {0};
for (int i = 1; i <= n; i++) {
if (i < m) continue;
bool flag = false;
for (int j = i - m; j < i; j++)
if (... | 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, arr[1001], l, r;
string s, t;
int main() {
cin >> n >> m >> q;
cin >> s >> t;
for (int i = 0; i <= n - m; i++) {
arr[i + 1] = arr[i];
if (s.substr(i, m) == t) {
arr[i + 1]++;
}
}
for (int j = 1; j <= q; j++) {
cin >> l >> r;
... | 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.*;
public class Main{
long mod = (int)1e9+7, IINF = (long)1e17;
final int MAX = (int)1e6+1, INF = (int)1e9, root = 3;
DecimalFormat df = new DecimalFormat("0.00000000");
double PI = 3.141592653589793238462643383279502884197169399375105820974944;
... | 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 | f = lambda: list(map(int, input().split())); ana1 = ""
n, m, q = f()
s = input()
t = input()
for _ in range(n - m + 1):
if s[_:_ + m] == t: ana1 += "1"
else: ana1 += "0"
for _ in range(q):
l, r = f()
if r - l + 1 >= m: print(ana1[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 | n,m,q=map(int,input().split())
s=input()
t=input()
a=[0]*n
for i in range(n-m+1):
if s[i:i+m]==t:
a[i]=1
for i in range(q):
u,v=map(int,input().split())
l=u-1
r=v-m
c=sum(a[l:r+1]) if l<=r else 0
print(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 | '''import sys,math
input = sys.stdin.readline
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(s[:len(s) - 1])
def invr():
return(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 | #include <bits/stdc++.h>
using namespace std;
const int MX = 1e3 + 10, MD = 1e9 + 7;
long long n, m, a[MX], ans, tmp, ps[MX], ps2[MX], q;
string s, t, k;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> q;
cin >> s >> t;
int flag = 0;
for (int i = 0; i < n; i++) {
ps[i + 1] += ps[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;
int kmp(string T, string &P) {
if (P.empty()) return 0;
if (T.size() < P.size()) return 0;
vector<int> prefix(P.size(), 0);
for (int i = 1, k = 0; i < P.size(); ++i) {
while (k && P[k] != P[i]) k = prefix[k - 1];
if (P[k] == P[i]) ++k;
prefix[i] = k;
}... | 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;
char S[1001], T[1001];
int A[1001], P[1001];
void f() {
for (int i = 0; i + M <= N; i++) {
int ok = 1;
for (int j = 0; j < M && ok; j++) ok = (S[i + j] == T[j]);
A[i] = ok;
}
}
int main(int argc, char **argv) {
ios::sync_with_stdio(false);
c... | 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 |
def main():
n, m, q = map(int, raw_input().split())
s = raw_input()
t = raw_input()
counts = [0]
_sum = 0
for i in xrange(len(s) - len(t) + 1):
flag = True
for j in xrange(len(t)):
if t[j] != s[i+j]:
flag = False
break
if fla... | 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;
char a[1005];
char b[1005];
int t[1005];
int sum[1005];
int main() {
memset(t, 0, sizeof(t));
int p, n, m;
cin >> n >> m >> p;
cin >> a >> b;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i + j] != b[j])
break;
else if (... | 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;
const int maxn = 1005;
char s[maxn], t[maxn];
int sum[maxn];
int main() {
scanf("%d%d%d", &n, &m, &q);
scanf("%s", s + 1);
scanf("%s", t + 1);
for (int i = 1; i <= n - m + 1; i++) {
bool f = 1;
for (int j = 1; j <= m; j++)
if (s[i + j - 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 | #include <bits/stdc++.h>
int n, m, q, nxt[1005], a[1005], b[1005], cnt;
char s[1005], t[1005];
inline void getnxt() {
nxt[0] = -1;
for (register int i = 1, tmp; i < m; i++) {
tmp = nxt[i - 1];
while (tmp >= 0 && t[tmp + 1] != t[i]) tmp = nxt[tmp];
if (t[tmp + 1] == t[i])
nxt[i] = tmp + 1;
else... | 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.*;
import java.util.*;
public class Main {
private static FastScanner in = new FastScanner();
private static FastOutput out = new FastOutput();
public void run() {
int n = in.nextInt(), m = in.nextInt(), q = in.nextInt();
String s = in.next(), t = in.next();
char[] 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 N = 1e3 + 7;
const int mod = 1e9 + 7;
char str[N];
char s[N];
int a[1000 + 7];
int main() {
int n, m, q;
scanf("%d%d%d", &n, &m, &q);
scanf("%s", str + 1);
scanf("%s", s + 1);
int ans = 0;
for (int i = 1; i <= n; i++) {
int cnt = 1;
while (str[... | 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 = list(map(int, input().split()))
s = input()
t = input()
ts = [1 if s[i:i+len(t)] == t else 0 for i in range(len(s)-len(t)+1)] + [0]*(len(t)-1)
sums = [ [0 for i in range(len(s))] for i in range(len(s)) ]
for i in range(n):
sums[i][i] = ts[i]
for i in range(n):
for j in range(i+1, n):
sums[i][j] = sums[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;
const long long N = 1e5 + 2;
const long long N1 = 1e2 + 2;
const long long mod = 1e9 + 7;
const int MASK = 1 << 17 + 1;
const int who = 6 * N * log2(N);
int a[N + 1];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, q;
cin >> n >> m >> q;
st... | 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.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class B {
InputStream is;
PrintWriter out;
String INPUT = "";
int KMPSearch(String pat, String txt)
{
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 | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
char a[1005];
char b[1005];
int t[1005];
int sum[1005];
int main() {
memset(t, 0, sizeof(t));
int p, n, m;
cin >> n >> m >> p;
cin >> a >> b;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i + 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 | n, m, q = map(int, input().split())
s1 = input()
s2 = input()
ans = []
for i in range(0, len(s1) - len(s2) + 1):
if s1[i:i + len(s2)] == s2:
ans.append(True)
else:
ans.append(False)
for i in range(q):
l, r = map(int, input().split())
if r - l + 1 < len(s2):
print(0)
cont... | 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 base = 317;
const int mod1 = 1e9 + 2277;
const int mod2 = 1e9 + 5277;
const int N = 1e3 + 5;
int n, m, q, dp[N][N];
string s, t;
pair<long long, long long> Hash_s[N], Hash_t[N], pw[N];
pair<long long, long long> get_hash_s(int l, int r) {
long long fi =
(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 | a,b,c=map(int,input().split())
str1=input()
str2=input()
string=''
for i in range(a-b+1):
if str1[i:i+b]==str2:
string+='1'
else:
string+='0'
for _ in range(c):
x,y=map(int,input().split())
if y-x+1>=b:
print(string[x-1:y-b+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 | n,m,q = map(int,input().split())
s = input()
t = input()
l = []
r = []
for i in range(n-m+1):
if s[i:i+m] == t:
l.append(i)
r.append(i+m-1)
for i in range(q):
x,y = map(int,input().split())
x-=1
y-=1
ans = 0
for j in range(len(l)):
if x <= l[j] and y >= r[j]:
... | 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;
/**
* @author khokharnikunj8
*/
public class Main {
public static void main(String[] args) {
... | 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 test
{
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int q = sc.nextInt();
sc.nextLine();
int arr[][] = new int[q][2];
String s = sc.nextL... | 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 mxN = 1e3 + 3;
bool cnt[mxN];
int sum[mxN];
int main() {
int n, m, a, i, j;
string s, ss;
cin >> n >> m >> a >> s >> ss;
for (i = 0; i < n - m + 1; i++) {
bool f = true;
for (j = 0; j < m; j++)
if (s[i + j] != ss[j]) {
f = 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 main() {
int n, q, m, i, j;
int dp[1010][1010];
int dp2[1010];
for (i = 0; i < 1010; i++) {
for (j = 0; j < 1010; j++) dp[i][j] = 0;
}
cin >> n >> m >> q;
string str1, str2;
cin >> str1;
cin >> str2;
int flag, k;
for (i = 0; i < n; i++) {
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 java.util.*;
public class segmanet
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int q=sc.nextInt();
String s=sc.next();
String t=sc.next();
... | 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 probB{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int q = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
String t = sc.nextLine();
int[] indices = new int[1000];
int[] sum_indices = ... | 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;
long long n, m, l, r, ss[10000001], q, a[10000001];
string second, t;
int main() {
cin >> n >> m >> q;
cin >> second >> t;
for (int i = 0; i < second.size(); i++) {
string st = "";
for (int j = i; j < second.size(); j++) {
st += second[j];
if (st =... | 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 main() {
int n, m, q, l, r;
cin >> n >> m >> q;
string a, b;
cin >> a >> b;
bool p[n + 1];
for (int i = 0; i < n + 1; i++) {
bool f = true;
for (int j = 0; j < m; j++)
if (a[i + j] != b[j]) {
f = false;
break;
}
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;
char s[1005], t[1005];
int pre[1005], q, n, m, a, b, prel[1005];
int main() {
scanf("%d%d%d", &n, &m, &q);
scanf("%s%s", &s[1], &t[1]);
for (int i = 1; i <= n; ++i) {
int j = 1, temp = i;
while (temp <= n && j <= m && t[j] == s[temp]) {
j++, temp++;
... | 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 | def ind(r,g,low,up):
if(up-low==0):
if(r[low]>g):
return(low)
else:
return(low+1)
elif(up-low==1):
if(r[low]>g):
return(low)
elif(r[low+1]>g):
return(low+1)
else:
return(low+2)
else:
k=((u... | 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>
int occ[10000];
using namespace std;
int main() {
int n, m, q;
int sol;
cin >> n >> m >> q;
string s1, s2;
cin >> s1 >> s2;
for (int i = 0; i < n; i++) {
bool test = true;
for (int j = 0; j < m; j++) {
if (s1[i + j] != s2[j]) {
test = false;
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;
int main() {
int n, m, q, l, r, index = 0, c = 0;
string s, t;
cin >> n >> m >> q >> s >> t;
bool a[n];
for (int i = 0; i < n; i++) {
index = 0;
for (int j = i; j < i + m; j++) {
if (s[j] == t[index])
index++;
else
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 |
import java.util.Scanner;
public class B {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt(), m = in.nextInt(), q = in.nextInt();
char[] s = in.next().toCharArray();
char[] t = in.next().toCharArray();
int[] a = new 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;
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>
using namespace std;
char s1[1005], s2[1005];
int s1len, s2len;
int Next[1005];
void kmp() {
int i = 0;
Next[i] = -1;
int j = -1;
while (i < s1len) {
if (j == -1 || s1[i] == s1[j]) {
i++;
j++;
Next[i] = j;
} else {
j = Next[j];
}
}
}
int main(void) ... | 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 int countSetBits(long long int n) {
long long int count = 0;
while (n) {
n &= (n - 1);
count++;
}
return count;
}
long long int power(long long int x, long long int y) {
if (y == 0)
return 1;
else if (y % 2 == 0)
return power(x, y / 2) ... | 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;
struct re {
int x, y, cs;
};
const long long module = 1000000000 + 7;
const int maxN = 1000 + 10;
int n, m, q, kq[maxN];
string s, t;
void nhap() { cin >> n >> m >> q >> s >> t; }
int kt(int x) {
for (int i = 1; i <= m - 1; ++i)
if (s[x + i] != t[i]) return (0);
r... | 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.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Comparator;
public class ECF48A {
public static void main(String[] args) throws Exception {
boolean local = System.getProperty("ONLINE_JUDG... | 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())
w = str(raw_input())
sw = str(raw_input())
t=[0]*n
t2=[0]*n
ile=0
p_ile = 0
for x in range(0, n-(m-1), +1):
ile = w.count(sw, x, x+m)
t[x]=ile
for y in range(0,len(t),+1):
if t[y]==1:
p_ile += 1
t2[y] = p_ile
tl=0
tp=0
for h in range(0, q, +1):
a,b=map(i... | 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, t;
cin >> n >> m >> t;
string a, b;
cin >> a >> b;
int begin[n];
int cumm[n];
memset(begin, 0, sizeof(begin));
for (int i = 0; i <= n - m; i++) {
bool match = true;
for (int j = i; j < i + m; j++) {
if (b[j - i] != a[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 | #include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
int n, m, q;
string s, t;
cin >> n >> m >> q;
cin >> s >> t;
for (int i = 0; i < n; i++) {
if (s.substr(i, m) == t)
v.push_back(1);
else
v.push_back(0);
}
while (q--) {
int left, right, ans = 0;
cin >> le... | 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()
w = s
ind = w.find(t)
a = []
st = [0]
en = [0]*(m-1)
count = 0
pred = 0
while ind != -1:
if len(a) > 0:
el = a[-1]
else:
el = -1
a.append(el + ind+1)
st += [count]*(el+ind+1-pred)
# print(count, el+ind+1-pred)
en += [coun... | 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()
ans=[0 for i in range(n)]
for i in range(n-m+1):
if a[i]==b[0]:
t=0
for j in range(1,m):
if a[j+i]!=b[j]:
t=1
break
if t==0:
ans[i]+=1
sub=[0]
for i in ans:
sub.append(sub[-1]+i)
fo... | 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 maxn = 1e3 + 5;
char s[maxn];
char t[maxn];
int ans[maxn];
int main() {
int n, m, q;
scanf("%d%d%d", &n, &m, &q);
int l, r;
int cnt = 0;
scanf("%s%s", s, t);
if (n < m) {
while (q--) {
printf("0\n");
}
return 0;
}
int flag;
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 | from itertools import accumulate
from sys import stdin
all_in = list(el.rstrip('\n') for el in stdin.readlines())
n, m, q = map(int, all_in[0].split())
s = all_in[1]
t = all_in[2]
l_r = [tuple(map(int, el.split())) for el in all_in[3:]]
in_ = [int(t == s[i: i + m]) for i in range(n - m + 1)]
acc = [0] + list(accumul... | 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()
arr = [0] * n
for i in range(n - m + 1):
if t == s[i:i+m]:
arr[i] = 1
if i: arr[i] += arr[i - 1]
for i in range(q):
l, r = list(map(int, input().split()))
l -= 1
r -= 1
L = l - 1
R = r - m + 1
if R < L:
pr... | 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;
cin >> n >> m >> q;
string s;
cin >> s;
string r;
cin >> r;
long long lps[m];
lps[0] = 0;
long long len = 0;
long long i = 1;
while (i < m) {
if (r[i] == r[len]) {
len++;
lps[i] = len;
i++;
} el... | 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(s) for s in input().split()]
s = input()
t = input()
a = []
b = []
for i in range(n):
b.append(0)
for i in range(n - m + 1):
if(s[i:(i+m)] == t):
a.append(i)
for i in a:
for j in range(i , n):
b[j] += 1
#print(a)
#print(b)
l = []
r = []
for i in range(q):
x,y = [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.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.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.StringTokenizer;... | 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()
wynik = ''
for i in range(0, n - m + 1):
if a[i : i + m] == b:
wynik += '1'
else: wynik += '0'
for i in range(q):
x , y = map(int, input().split())
if y - x + 1 >= m:
print(wynik[x - 1 : y - 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 main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, q;
cin >> n >> m >> q;
string s, t;
cin >> s >> t;
vector<int> k(n, false);
for (int i = 0; i < n; ++i) {
bool flag = true;
for (int j = 0; j < m; ++j) {
if (i + j >= 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 | f = lambda: map(int, input().split())
n, m, q = f()
s = input()
sb = input()
indexes = ''
for i in range(n - m + 1):
sec_i = i + m
if s[i:sec_i] == sb:
indexes += '1'
else:
indexes += '0'
for j in range(q):
l, r = f()
l -= 1
print(indexes[l:max(r - m + 1, 0)].count('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 sys import stdin
def main():
n, m, q = map(int, input().split())
s, t = input(), input()
field = []
i, j, c = -1, 0, 0
m -= 1
while True:
j = s.find(t, i + 1)
if j != -1:
field += [c] * (j - i)
i = j
c += 1
else:
fiel... | 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.*;
import java.lang.*;
public class occurrences{
public static void main(String[] args)
{
FastReader f = new FastReader();
PrintWriter wr = new PrintWriter(System.out);
int n,m,q;
n=f.nextInt();
m=f.nextInt();
q=f.nextInt();
char[] ... | 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.*;
public class Mainn {
FastReader scn;
PrintWriter out;
String INPUT = "";
void solve() {
int n = scn.nextInt(), m = scn.nextInt(), q = scn.nextInt(), ind = 0;
String str = scn.next(), s = scn.next();
int[] arr = new int[n];
while(str.indexOf(s, ind) != -1) {
ind = 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 | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class Main implements Runnable {
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numCha... | 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()
x=[]
for i in range(n):
x.append([0]*n)
for i in range(n-m+1):
if s[i:i+m]==t:
x[i][i+m-1]=1
for j in range(m,n):
for i in range(n-j):
x[i][i+j]=x[i+1][i+j]+x[i][i+j-1]
if j>1:
x[i][i+j]-=x[i+1][i+j-1]
for i in range(q):
a,b=map(int,input().split())
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()
if m == 0 or n == 0 or n < m:
for i in range(q):
print('0')
exit()
occur = [0]*(n-m+1)
for i in range(n-m+1):
if s[i:i+m] == t:
occur[i] = occur[i-1] + 1 if i > 0 else 1
else:
occur[i] = occur[i-1] if i > 0 else 0
oc... | 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.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
public class B {
public static void main(String args[])
{
FastReader Reader=new FastReader(System.in);
int N=Reader.nextInt();
int M=Read... | 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.Scanner;
public class B1016 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt(), m = in.nextInt(), q = in.nextInt(), i, j, count = 0, lastIndex = -1, currIndex = -1;
String s = in.next(), t = in.next();
boolean[] query = new boolean[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 n, m, s;
string a, b;
int num[200005];
int t = 0;
cin >> n >> m >> s;
cin >> a >> b;
for (int i = 0; i < n; i++) {
int flag = 0;
for (int j = 0; j < m; j++) {
if (a[i + j] != b[j]) {
flag = 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 | import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import static java.lang.Math.*;
public class SegmentOccurrences implements Closeable {
private InputRead... | 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.io.PrintWriter;
import java.util.*;
public class B {
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(... | 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 | //package CodeForces.EducationalRound48;
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
public class B {
public static void main(String[] args) {
sc sc = new sc();
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int n = sc.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 | from __future__ import division, print_function
def main():
n, m, q = map(int, input().split())
s = input()
t = input()
ans = []
i, cnt = 0, 0
while 1:
si = s.find(t, i)
if si != -1:
for _ in range(si - i + 1):
ans.append(cnt)
cnt += 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 | #include <bits/stdc++.h>
using namespace std;
const long long M = 1000005;
int occur[1005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, q;
string s, t;
cin >> n >> m >> q;
cin >> s >> t;
for (int i = 0; i < n - m + 1; i++) {
if (s.substr(i, m) == t) {
occur[i + 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=input()
t=input()
x=0
dp1=[]
while x<n:
if s[x-m+1:x+1]==t:
dp1.append(1)
else:
dp1.append(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+=dp1[j]
... | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.