output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> using namespace std; void qmax(int &x, int y) { if (x < y) x = y; } void qmin(long long &x, long long y) { if (x > y) x = y; } inline long long read() { char s; long long k = 0, base = 1; while ((s = getchar()) != '-' && s != EOF && !(isdigit(s))) ; if (s == EOF) exit(0); if (...
### Prompt Please create a solution in cpp to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; int N, M, Q; string S, T; int ok[1010]; void solve() { int i, j, k, l, r, x, y; string s; cin >> N >> M >> Q >> S >> T; for (i = 0; i < (N); i++) { ok[i + 1] = ok[i]; if (i + M <= N) { x = 1; for (j = 0; j < (M); j++) if (S[i + j] != T[j]...
### Prompt In Cpp, your task is to solve the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a...
#include <bits/stdc++.h> using namespace std; int main() { string s, t; int n, m, q, l, r; cin >> n >> m >> q; cin >> s >> t; int arr[10000] = {0}; for (int i = 0; i <= n - m; ++i) { arr[i + 1] = arr[i] + (s.substr(i, m) == t); } while (q--) { cin >> l >> r; if (r - l + 1 < m) cout << ...
### Prompt Please create a solution in CPP to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; int n, m, pre[2005], q; char s[2005], t[2005]; int main() { scanf("%d%d%d", &n, &m, &q); scanf("%s%s", s, t); for (int i = 0; i < n - m + 1; i++) { int flag = 1; for (int j = 0; j < m; j++) if (s[i + j] != t[j]) { flag = 0; break; }...
### Prompt Your task is to create a CPP solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of st...
#include <bits/stdc++.h> using namespace std; int n, m, Q, cnt = 0; int a[1010], L[1010]; char s[1010], t[1010]; int main() { scanf("%d%d%d", &n, &m, &Q); scanf("%s%s", s, t); for (int i = 0; i < n; i++) { if (s[i] == t[0]) { bool bo = 0; for (int j = 1; j < m; j++) { if (s[i + j] != t[j])...
### Prompt Develop a solution in Cpp to the problem described below: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m, q; string s, t; cin >> n >> m >> q >> s >> t; map<long long, long long> d; long long cont = 0; for (long long i = (0); i < (long long)(n); i++) { if (s.substr(i, m) == t...
### Prompt Develop a solution in CPP to the problem described below: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; int fx[] = {-1, 1, 0, 0}; int fy[] = {0, 0, -1, 1}; int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; int kx[] = {1, 1, -1, -1, 2, 2, -2, -2}; int ky[] = {2, -2, 2, -2, 1, -1, 1, -1}; bool cmp(const pair<int, int> &a, const pair<int, int> &b) {...
### Prompt Please formulate a CPP solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int main() { int n, m, q; cin >> n >> m >> q; string a, b; cin >> a >> b; int mark[1000]; memset(mark, 0, sizeof(mark)); for (int i = 0; i < n; i++) { if (a[i] == b[0]) { int flag = 1, j; for (j = 1; j < m && i + j <...
### Prompt Construct a CPP code solution to the problem outlined: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3 + 5; char a[maxn], b[maxn]; int sum[maxn]; int n, m, q; void solve() { for (int i = 0; i < n; i++) { int flag = 1; for (int j = 0; j < m; j++) if (a[i + j] != b[j]) { flag = 0; break; } if (flag) sum[i + 1]++; ...
### Prompt Generate a CPP solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a st...
#include <bits/stdc++.h> using namespace std; int n, m, q; int ans[1005]; int main() { while (scanf("%d%d%d", &n, &m, &q) != EOF) { string s1, s2; cin >> s1 >> s2; for (int i = 0; i + m <= n; i++) { if (s1.substr(i, m) == s2) ans[i + 1]++; } for (int i = 2; i <= n; i++) ans[i] += ans[i - 1];...
### Prompt In Cpp, your task is to solve the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a...
#include <bits/stdc++.h> using namespace std; char s[1002], t[1002]; int v[1002]; int main() { int n, m, q, l, r, sol, i, ok, j; cin >> n >> m >> q; cin.get(); cin.getline(s, 1001); cin.getline(t, 1001); for (i = 0; i < n - m + 1; i++) { ok = 1; for (j = i; j <= i + m - 1; j++) if (t[j - i] !=...
### Prompt Generate a CPP solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a st...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const long long INF = 1LL << 60; const long long mod = 1e9 + 7; const long double eps = 1e-8; const long double pi = acos(-1.0); template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <cl...
### Prompt Your task is to create a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of st...
#include <bits/stdc++.h> using namespace std; void z_function(string &s, vector<int> &z) { int n = s.length(), l = -1, r = -1; z.clear(); z.resize(n, 0); z[0] = n; for (int i = 0; i < n; i++) { if (i <= r) z[i] = min(r - i + 1, z[i - l]); while (z[i] + i < n && s[z[i]] == s[z[i] + i]) z[i]++; if (...
### Prompt Create a solution in cpp for the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a ...
#include <bits/stdc++.h> using namespace std; const int MX = 1e3; int sum[MX + 2]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, m, q, l, r; string str, str2; cin >> n >> m >> q; cin >> str >> str2; for (long long i = 0; i < n - m + 1; i++) { sum[i] = (str.substr(i, m) == ...
### Prompt In Cpp, your task is to solve the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a...
#include <bits/stdc++.h> using namespace std; vector<int> vet; int p[201010]; void kmp(string &s, int sz) { p[0] = 0; int idx = 0, n = (int)s.size(); for (int i = 1; i < n; i++) { while (s[idx] != s[i] && idx > 0) idx = p[idx - 1]; if (s[idx] == s[i]) idx++; p[i] = idx; if (p[i] == sz) { vet...
### Prompt Please formulate a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) using namespace std; const int N = 1e3 + 5; int sum[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int n, m, q, l, r; string s, t; cin >> n >> m >> q; cin >> s >> t; for (int i = ...
### Prompt Generate a CPP solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a st...
#include <bits/stdc++.h> using namespace std; const double PI = 2 * acos(0.0), EPS = 1e-9; const int INF = 1e9, NINF = -1e9, MOD = 1e9 + 7; void GO() { cout << fixed << setprecision(10); } int main() { GO(); int n, m, q, r, l, c, a[1001] = {}; string second, t; cin >> n >> m >> q >> second >> t; for (int i = ...
### Prompt Your challenge is to write a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences o...
#include <bits/stdc++.h> using namespace std; const int N = 1111; string s, t; int sum[N]; int n, m, q; signed main() { ios_base::sync_with_stdio(false); cin >> n >> m >> q >> s >> t; for (int i = (1); i <= (n); i++) { bool found = true; for (int j = (0); j <= (m - 1); j++) { int ii = i - 1 + j; ...
### Prompt Your task is to create a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of st...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int maxn = 1010; char a[maxn], b[maxn]; int n, m, q; vector<int> pos; void solve() { while (q--) { int l, r, tr; scanf("%d%d", &l, &r); tr = r - m + 1; if (l > tr) puts("0"); else { printf("%d\n", ...
### Prompt Your task is to create a cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of st...
#include <bits/stdc++.h> using namespace std; int n, m, q, dp[10004]; string s, t; int main() { cin >> n >> m >> q >> s >> t; for (int i = 0, ok = true; i <= n - m; ++i, ok = true) { for (int j = 0; j < m; ++j) { if (s[i + j] != t[j]) ok = false; } dp[i + 1] = dp[i] + ok; } for (int i = 0, l, ...
### Prompt Please create a solution in Cpp to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, q; cin >> n >> m >> q; string s1, s2; cin >> s1 >> s2; int occ[n]; int sta[n]; int sum[n]; for (int o = 0; o < n; o++) { occ[o] = 0; sum[o] = 0; sta[o] = 0; } int v = 0; for (int e = 0; e < n - m + 1; e++) { int f...
### Prompt Create a solution in CPP for the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a ...
#include <bits/stdc++.h> int n, m, q, a0, a1; char s[1003], t[1003]; int pp[1003]; int main() { scanf("%d %d %d", &n, &m, &q); scanf("%s", s); scanf("%s", t); for (int i = 0; i <= n - m; ++i) { int j = 0; for (; j < m && s[i + j] == t[j]; ++j) ; if (j == m) pp[i] = 1; } for (int i = 1; i <...
### Prompt Create a solution in CPP for the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a ...
#include <bits/stdc++.h> using namespace std; int z[1000005]; string s; void Z() { int n = s.size(), l = 0, r = 0, i; for (i = 0; i < n; i++) { if (i > r) { l = r = i; while (r < n && s[r] == s[r - l]) { r++; } z[i] = r - l; r--; } else { if (i + z[i - l] <= r) { ...
### Prompt Generate a cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a st...
#include <bits/stdc++.h> using namespace std; vector<int> l, r; int main() { string s, t; int n, m, q, x, y; cin >> n >> m >> q >> s >> t; for (int i = 0; i < n; i++) { int flag = 1; if (s[i] == t[0]) { for (int j = i, k = 0; j < n && k < m; j++, k++) if (s[j] != t[k]) { flag = 0...
### Prompt Construct a CPP code solution to the problem outlined: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in...
#include <bits/stdc++.h> using namespace std; const int64_t MOD = 1e9 + 7; const int64_t N = 2e6; bool isQuery = false; int64_t power(int64_t x, int64_t n) { if (n == 0) return 1; else if (n % 2 == 0) return power(x, n / 2) * power(x, n / 2); else return x * power(x, n / 2) * power(x, n / 2); } int64_...
### Prompt Your task is to create a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of st...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, i, q, j, k, l, count, c, p = 0, a[1001] = {0}; cin >> n >> m >> q; string s, t; cin >> s >> t; for (i = 0; i <= n - m; i++) { if (s.substr(i, m) == t) a[i] = {1}; } for (i = 1; i <= q; i++) { long long d, e; c = 0; ...
### Prompt Please formulate a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; int n, m, q; string s; string t; int d[1001]; bool check(string s) { for (int i = 0; i < s.length(); i++) { if (s[i] != t[i]) return false; } return true; } int main() { cin >> n >> m >> q; cin >> s >> t; for (int i = 0; i < n - m + 1; i++) { string tmp ...
### Prompt Please create a solution in Cpp to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; int a[1001]; int main() { int i, n, m, q, j, l, r; string str1, str2; cin >> n >> m >> q; cin >> str1; cin >> str2; for (i = 0; i <= n - m; i++) { for (j = 0; j < m; j++) { if (str1[i + j] != str2[j]) { break; } } if (j == m) a[i ...
### Prompt Create a solution in Cpp for the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a ...
#include <bits/stdc++.h> using namespace std; const int maxn = 10005; int Next[maxn]; char str[maxn], th[maxn]; int change(char s[]) { int i = 0, j = 1; Next[i] = 0; while (s[j]) { if (s[i] == s[j]) { i++; Next[j] = i; j++; } else { if (i > 0) { i = Next[i - 1]; } els...
### Prompt Create a solution in CPP for the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, q; string s, t; cin >> n >> m >> q; cin >> s >> t; vector<int> v; v.clear(); if (n < m) { for (int i = 0; i < q; i++) { int a, b; cin >> a >> b; cout << "0" << endl; } return 0; } for (int i = 0; i <= s....
### Prompt In cpp, your task is to solve the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a...
#include <bits/stdc++.h> using namespace std; int n, m, q, sum[1001]; string s1, s2; int main() { cin >> n >> m >> q >> s1 >> s2; for (int i = 1; i <= n; i += 1) { sum[i] += sum[i - 1]; if (i > n - m + 1) { continue; } bool f = true; for (int j = i; j < i + m; j += 1) { if (s1[j - 1]...
### Prompt Please formulate a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; int n, m, q; char s[1005], t[1005]; int sum[1005]; int main() { scanf("%d%d%d", &n, &m, &q); scanf(" %s %s", s + 1, t + 1); for (int i = 1; i <= n; i++) { int good = 1; for (int j = 1; j <= m; j++) { if (s[i + j - 1] != t[j]) good = 0; } sum[i] =...
### Prompt Generate a CPP solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a st...
#include <bits/stdc++.h> using namespace std; int dp[2000]; char str[2000], tr[2000]; int main() { int i, j, k, l, m, n, q; scanf("%d%d%d", &n, &m, &q); scanf("%s", str + 1); scanf("%s", tr + 1); for (int i = 1; str[i]; i++) { for (j = 1, k = i; tr[j] && str[k]; j++, k++) { if (tr[j] != str[k]) brea...
### Prompt Create a solution in Cpp for the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1001; int a[maxn], cnt = 0; char s1[maxn], s2[maxn]; int main() { int n, m, q; scanf("%d%d%d", &n, &m, &q); cin >> s1 >> s2; for (int i = 0; i < n; i++) { if (s1[i] == s2[0]) { bool fa = 1; int now = i; for (int j = 1; j < m; j...
### Prompt Your challenge is to write a CPP solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences o...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long z[3000019], arr[3000019], pre[3000019]; void fnc(string s) { memset(z, 0, sizeof(z)); long long l = 0, r = 0; long long n = s.size(); for (long long i = 1; i <= n; i++) { if (i <= r) z[i] = min(r - i + 1, z[i - l]); whil...
### Prompt Please provide a CPP coded solution to the problem described below: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences o...
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { int64_t n, m, q; string s, t; cin >> n >> m >> q >> s >> t; vector<pair<int, int>> ins; for (int i = 0; i < s.size(); ++i) { if (i + t.size() - 1 < s.size() && s.substr(i, t.size()) == t) { ins.push_back(make_pair...
### Prompt Construct a cpp code solution to the problem outlined: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, q; cin >> n >> m >> q; string s, t; cin >> s >> t; vector<int> I; for (int i = 0; i < n - m + 1; i++) { if (t == s.substr(i, m)) I.push_back(i); } for (int i = 0; i < q; i++) { int l, r; cin >> l >> r; l--; r--; ...
### Prompt Your challenge is to write a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences o...
#include <bits/stdc++.h> using namespace std; void solve() { int n, m, q; cin >> n >> m >> q; string s, t; cin >> s >> t; vector<int> v; for (int i = 0; i < int((s).size()); i++) { int j; for (j = 0; j < int((t).size()) && (i + j) < int((s).size()); j++) { if (s[j + i] != t[j]) break; } ...
### Prompt Please formulate a cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; int n, m, q, dp[1010][1010]; char s[1010], t[1010]; bool used[1010]; int main() { scanf("%d%d%d", &n, &m, &q); scanf("%s", s + 1); scanf("%s", t); for (int i = 1; i + m - 1 <= n; i++) { bool f = true; for (int j = 0; j < m; j++) { if (s[i + j] != t[j])...
### Prompt Please provide a cpp coded solution to the problem described below: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences o...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, q; cin >> n >> m >> q; string s, t; cin >> s >> t; vector<bool> occ(n); for (int i = 0; i < n; i++) { if (s.substr(i, m) == t) { occ[i] = 1; } } vector<int> prefixOcc(n + 1); prefixOcc[0] = 0; for (int i = 1; i <= n; ...
### Prompt Generate a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a st...
#include <bits/stdc++.h> using namespace std; string s, t; long long m, n, q, dp[1010][1010]; int main() { cin >> n >> m >> q; cin >> s >> t; for (int i = 0; i <= n - m; i++) { bool b = false; for (int j = i; j < i + m; j++) { if (s[j] != t[j - i]) b = true; } if (b == false) { dp[i][i...
### Prompt Your task is to create a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of st...
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; vector<long long> build(string s) { int n = s.size(); vector<long long> kmp(n, 0); for (int i = 1; i < n; i++) { int j = kmp[i - 1]; while (j > 0 && s[i] != s[j]) { j = kmp[j - 1]; } if (s[i] == s[j]) j++; kmp[i] = j;...
### Prompt Create a solution in cpp for the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 20; int sum[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, q; cin >> n >> m >> q; string s, t; cin >> s >> t; for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + (i + m <= n && s.substr(i, m)...
### Prompt Create a solution in Cpp for the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, q; cin >> n >> m >> q; string s; cin >> s; string t; cin >> t; string str1 = s; size_t pos1; vector<long long> arr; pos1 = str1.find(t); while (pos1 != string::npos) { arr.push_back(pos1); pos1 = str1.find(t, pos1 +...
### Prompt Please provide a Cpp coded solution to the problem described below: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences o...
#include <bits/stdc++.h> using namespace std; const int64_t MOD = 1e9 + 7; const int64_t N = 2e6; bool isQuery = false; int64_t power(int64_t x, int64_t n) { if (n == 0) return 1; else if (n % 2 == 0) return power(x, n / 2) * power(x, n / 2); else return x * power(x, n / 2) * power(x, n / 2); } int64_...
### Prompt Generate a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a st...
#include <bits/stdc++.h> using namespace std; int st[1001]; int main() { int n, m, q; cin >> n >> m >> q; string s; cin >> s; string t; cin >> t; st[0] = 0; for (int i = 1; i <= n - m + 1; i++) { bool b = true; for (int j = i; j < i + m; j++) { if (s.at(j - 1) != t.at(j - i)) { b =...
### Prompt Your task is to create a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of st...
#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; ...
### Prompt Your challenge is to write a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences o...
#include <bits/stdc++.h> using namespace std; int n, m, q, lct1, lct2; string s, t; int z[3005]; int cnt; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n >> m >> q; cin >> s >> t; s = t + s; int len = s.length(); z[0] = 0; for (int i = 1, l = 0, r = 0; i < len; ++i) ...
### Prompt Develop a solution in Cpp to the problem described below: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; struct Node { int d; struct Node *left, *right; }; int p[1000][1000] = {0}; string s, t; void dp(int i, int j) { if (j - i + 1 == t.size()) { int f = 1; for (int z = 0; z < t.size(); z++) { if (s[i + z] != t[z]) { f = 0; break; } ...
### Prompt Create a solution in CPP for the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a ...
#include <bits/stdc++.h> using namespace std; string s, t; vector<int> can; int n, m, k; int main() { cin >> n >> m >> k; cin >> s >> t; for (int i = 0; i <= n - m; i++) { if (s.substr(i, m) != t) continue; can.push_back(i + 1); } while (k--) { int l, r; cin >> l >> r; r = r - m + 1; i...
### Prompt Please create a solution in Cpp to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; int n, m, q, l, r, vf, ans, i, j, k; const int LMAX = 1e3; char s[LMAX + 5], t[LMAX + 5]; int st[LMAX + 5], dr[LMAX + 5], cnt = 0; int main() { cin >> n >> m >> q; for (i = 1; i <= n; i++) cin >> s[i]; for (i = 1; i <= m; i++) cin >> t[i]; for (i = 1; i <= n - m + 1...
### Prompt Please provide a CPP coded solution to the problem described below: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences o...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s, t; int n, m, q, ct = 0, flag, l, r; cin >> n >> m >> q; vector<vector<int>> ans(n + 1, vector<int>(n + 1, 0)); cin >> s; cin >> t; for (int i = 0; i < n; i++) { flag = 1; for (...
### Prompt Please create a solution in cpp to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; string str; vector<int> z; int len = 0; void zfunc() { len = str.size(); z.resize(len); int ind = 0; for (int i = 1; i < len; i++) { if (ind + z[ind] - 1 >= i) { z[i] = min(ind + z[ind] - i, z[i - ind]); } for (; i + z[i] < len && str[i + z[i]] == ...
### Prompt Please formulate a cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; char s[100005], t[100005]; int Q, m, n, l1, l2; int sum[100005], fr[100005], ma[100005]; void init() { int i, np; scanf("%d%d%d", &l1, &l2, &Q); scanf("%s", s); scanf("%s", t); for (i = l1; i > 0; i--) s[i] = s[i - 1]; for (i = l2; i > 0; i--) t[i] = t[i - 1]; ...
### Prompt Create a solution in cpp for the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a ...
#include <bits/stdc++.h> using namespace std; long long ans[1005]; int main() { long long n, m, k; string a, b; cin >> n >> m >> k; cin >> a >> b; for (int i = 0; i <= n - m; i++) { ans[i + 1] = ans[i] + (a.substr(i, m) == b); } while (k--) { long long l, r; cin >> l >> r; if (r - l + 1 < ...
### Prompt Please formulate a CPP solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 10; int main() { int n, q, g; int index; int a[1005]; int k = 0; string s, t; string ss[1005]; scanf("%d%d%d", &n, &q, &g); getchar(); cin >> s >> t; for (int i = 0; i < n; i++) { string str = s.substr(i, q); if (str == t)...
### Prompt Please formulate a cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; int arr[1001] = {0}; int u[200001] = {0}; int main() { ios::sync_with_stdio(false); int n, m, q, i, l, r; cin >> n >> m >> q; string s, t, ch; cin >> s >> t; int pos = -1, x = 0; while (pos + 1 < s.size() && s.find(t, pos + 1) != string::npos) { pos = s.fi...
### Prompt Please formulate a cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#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]; ...
### Prompt Please formulate a cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; inline int two(int n) { return 1 << n; } inline void set_bit(int& n, int b) { n |= two(b); } inline void unset_bit(int& n, int b) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } template <class T> T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a % b) : a);...
### Prompt Your challenge is to write a cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences o...
#include <bits/stdc++.h> using namespace std; int n, m, q; char a[1005], b[1005]; struct qujian { int s, e; }; qujian qq[10005]; int num = 0; int main() { scanf("%d%d%d", &n, &m, &q); scanf("%s\n%s", a, b); if (n < m) { for (int i = 0; i < q; i++) { int x, y; scanf("%d%d", &x, &y); printf(...
### Prompt Develop a solution in cpp to the problem described below: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 10; string s1, s2; int ans[maxn]; int main() { int n, m, q; cin >> n >> m >> q; cin >> s1 >> s2; memset(ans, 0, sizeof(ans)); for (int i = 0; i + m <= n; i++) { if (s1.substr(i, m) == s2) { ans[i + 1]++; } } for (int i = 1;...
### Prompt Create a solution in Cpp for the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a ...
#include <bits/stdc++.h> using namespace std; int const lmt = 1e5 + 4; long long pre[lmt]; int main() { int n, m, q; cin >> m >> n >> q; string s, t; cin >> s >> t; string tt = t + '#' + s; int len = tt.length(); int f[len]; int j = 0; f[0] = 0; for (int i = 1; i < len; i++) { j = f[i - 1]; ...
### Prompt Your task is to create a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of st...
#include <bits/stdc++.h> using namespace std; string s, t; int n, m, q; int v[100000] = {}; void match() { for (int i = 0; i <= n - m; i++) { v[i + 1] = v[i] + (s.substr(i, m) == t); } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; cin >> n >> m >> q; cin >> s; cin >> ...
### Prompt Construct a CPP code solution to the problem outlined: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 10; char str[maxn], s[maxn]; struct node { char ch; int val; node() {} node(char _ch, int _val) : ch(_ch), val(_val) {} }; node stk[maxn]; int top; int f[maxn]; int tr[maxn]; int len1, len2; void update(int x, int v) { while (x <= len1) { ...
### Prompt Construct a Cpp code solution to the problem outlined: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1005, MAXM = 1005; string T, P, tt; int Next[MAXM], N, M, C; void MakeNext(int M) { int i = 0, j = -1; Next[i] = -1; while (i < M) { if (j == -1 || P[i] == P[j]) Next[++i] = ++j; else j = Next[j]; } } int KMP(int pos, int N, int ...
### Prompt Your task is to create a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of st...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, q; cin >> n >> m >> q; string s, t; cin >> s >> t; int ans[1000003] = {0}; for (int i = 0; i < n; i++) { if (s.substr(i, m) == t) { ans[i] = 1; } } while (q--) { int l, r, cnt = 0; cin >> l >> r; if (r - l + 1...
### Prompt Please create a solution in CPP to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; string a; string b; int ans[1000 + 7]; int main() { int m, n, q; cin >> m >> n >> q; cin >> a >> b; int tmp = 0; for (int i = 0; i < m; i++) { if (a[i] == b[0]) { int cnt = 0; for (int j = 0; j < n; j++) { if (a[i + j] == b[j]) cn...
### Prompt In cpp, your task is to solve the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a...
#include <bits/stdc++.h> #pragma GCC optimize("O3", "unroll-loops") using namespace std; template <class T1, class T2> inline void checkmin(T1 &x, T2 y) { if (x > y) x = y; } template <class T1, class T2> inline void checkmax(T1 &x, T2 y) { if (x < y) x = y; } template <class T1> inline void sort(T1 &arr) { sort(...
### Prompt Your challenge is to write a cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences o...
#include <bits/stdc++.h> using namespace std; const int MaxN = 100005; int BIT[MaxN]; void update(int pos) { int i, j, p, q; for (i = pos; i < MaxN; i += i & (-i)) { BIT[i] += 1; } } int query(int pos) { int i, j, p = 0, q; for (i = pos; i > 0; i -= i & (-i)) { p += BIT[i]; } return p; } int main(...
### Prompt Your task is to create a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of st...
#include <bits/stdc++.h> using namespace std; char s[2000], t[2000]; int f[2000]; int main() { int n, m, q; scanf("%d%d%d", &n, &m, &q); scanf("%s", s + 1); scanf("%s", t + 1); for (int i = 1; i <= n - m + 1; i++) { int flag = 1; for (int j = 1; j <= m; j++) if (s[i + j - 1] != t[j]) { f...
### Prompt Your challenge is to write a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences o...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n, m, l, r, q, nr; string s; string t; cin >> n >> m >> q; cin >> s >> t; int cnt[1001] = {0}; for (int i = 0; i <= n - m; i++) { if (s.substr(i, m) == t) { cnt[i] = 1; } } l = 0; r = 0; for (i = 1; i <= q; i++) { ...
### Prompt Generate a CPP solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a st...
#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; ...
### Prompt Construct a cpp code solution to the problem outlined: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in...
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const long long MAXN = 1e3 + 10; long long n, m, q; string a, b; long long pref[MAXN]; inline void precalc() { for (long long i = 0; i < n - m + 1; ++i) { bool flag = true; for (long long j = i; j < i + m; ++j) { if (a[j] != b[j - ...
### Prompt Create a solution in Cpp for the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a ...
#include <bits/stdc++.h> using namespace std; void add_self(int& a, int b) { a += b; if (a >= (int)1e9 + 7) a -= (int)1e9 + 7; } void solve() { int n, m, q; cin >> n >> m >> q; string s, t; cin >> s >> t; vector<int> a(n + 1, 0); int cnt = 0; for (int i = 0; i <= n - m; i++) { bool ok = true; ...
### Prompt Develop a solution in cpp to the problem described below: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; const int mxn = 1e3 + 5, seed = 131, seed2 = 31, MOD = 1e9 + 9; int n, m, q; string s, t; long long p[mxn], pp[mxn], a[mxn], aa[mxn], b[mxn], bb[mxn]; inline long long strHash(int l, int r) { return (long long)((1LL * a[r] - 1LL * a[l - 1] * p[r - l + 1] % MOD) + MOD) % ...
### Prompt Your challenge is to write a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences o...
#include <bits/stdc++.h> using namespace std; int match[1009]; int prefix[1009]; string s, t; bool isMatch(int a) { for (int i = 0; i < t.size(); i++) { if (i + a >= s.size() || s[i + a] != t[i]) { return false; } } return true; } int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >...
### Prompt Construct a cpp code solution to the problem outlined: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, q, t = 0; string a, b, s = ""; cin >> n >> m >> q >> a >> b; vector<pair<int, int> > v; while (t + b.size() - 1 < a.size()) { if (a.substr(t, b.size()) == b) { v.push_bac...
### Prompt In CPP, your task is to solve the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a...
#include <bits/stdc++.h> using namespace std; string s, t; int ans[100009]; int lps[100009]; int main() { int n, m, q; cin >> n >> m >> q; cin >> s >> t; int sz = t.size(); int sz1 = s.size(); for (int i = 1; i <= (sz1 + 1 - sz); i++) { int flag = 0; string sb = s.substr(i - 1, sz); if (sb == t)...
### Prompt Please formulate a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, q, i, j, l, r, a[5000]; string s, t; cin >> n >> m >> q; cin >> s >> t; if (m > n) goto label; if (s.compare(0, m, t) == 0) { a[0] = 1; } else a[0] = 0; for (j = 1; j <= n - m + 1; j++) { if (s.compare(j, m, t) == 0) ...
### Prompt Create a solution in Cpp for the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a ...
#include <bits/stdc++.h> using namespace std; int max(int a, int b) { return (a > b) ? a : b; } int min(int a, int b) { return (a < b) ? a : b; } int main() { int n, m, k; cin >> n >> m >> k; string s, t; cin >> s; cin >> t; unordered_map<char, int> umap; vector<int> skips; for (int i = 0; i < t.size();...
### Prompt Generate a CPP solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a st...
#include <bits/stdc++.h> using namespace std; const long long mod[] = {(long long)1e9 + 7, (long long)1e9 + 9, (long long)1e9 + 21, (long long)1e9 + 33}; const int maxn = 2e3 + 5; const int Nmod = 3; string a, b; int i, j, n, m, q; long long Pow[Nmod][maxn]; static long long Hash[Nmod][maxn], H...
### Prompt Develop a solution in cpp to the problem described below: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10; int main() { ios_base::sync_with_stdio(false); int n, m, q, l, r, tlen, cnt; char s[N], t[N]; bool match[N] = {0}; cin >> n >> m >> q >> s >> t; tlen = strlen(t); for (int i = 0; s[i]; ++i) { match[i] = !strncmp(s + i, t, tlen); }...
### Prompt Construct a cpp code solution to the problem outlined: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in...
#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...
### Prompt Create a solution in cpp for the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a ...
#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 -...
### Prompt Generate a CPP solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a st...
#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; ...
### Prompt Create a solution in CPP for the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a ...
#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...
### Prompt Please formulate a CPP solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#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...
### Prompt Your challenge is to write a cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences o...
#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...
### Prompt Please provide a cpp coded solution to the problem described below: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences o...
#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 ...
### Prompt Please provide a CPP coded solution to the problem described below: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences o...
#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...
### Prompt Your challenge is to write a CPP solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences o...
#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 =...
### Prompt Develop a solution in CPP to the problem described below: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#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++) ...
### Prompt Develop a solution in CPP to the problem described below: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#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 ...
### Prompt Create a solution in Cpp for the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a ...
#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 ...
### Prompt Develop a solution in Cpp to the problem described below: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#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) >...
### Prompt Please formulate a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#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); ...
### Prompt Please formulate a CPP solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a...
#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,...
### Prompt Please provide a CPP coded solution to the problem described below: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences o...
#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...
### Prompt Generate a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a st...
#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...
### Prompt Generate a Cpp solution to the following problem: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a st...
#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++...
### Prompt Please provide a Cpp coded solution to the problem described below: You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences o...