This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define rrep(i,a,b) for(int i=int(a);i>int(b); i--);
#define all(v) v.begin(),v.end()
#define trav(a,v) for(auto&a:v)
using namespace std;
const long long inf = 1e15;
typedef long long ll;
int main() {
cin.sync_with_stdio(false);
ll n, l;
cin >> n >> l;
vector<ll> s(n);
rep(i, 0, n)cin >> s[i];
ll q;
cin >> q;
ll i = 1, j = 0;
vector<ll> p(s.size());
while (i < s.size()) {
if (s[i] == s[j]) {
j++;
p[i] = j;
}
else {
while (j) {
if (s[j - 1] == s[i])break;
j = p[j - 1];
}
p[i] = j;
}
i++;
}
rep(Q, 0, q) {
vector<ll> res(n - l + 1, -1);
ll k;
cin >> k;
rep(start, 0, n - l + 1) {
i = 0;
j = 0;
ll cur = 0;
while (i < s.size()) {
if (s[i] == s[start + j]) {
if (s[i] != s[start + j])cur++;
i++;
j++;
}
if (j == l) {
res[start]++;
j = p[j - 1];
}
else if (i < s.size() && s[start + j] != s[i]) {
cur--;
if (j)j = p[j - 1];
else i++;
}
}
}
trav(a, res)cout << a << " ";
cout << endl;
}
return 0;
}
Compilation message (stderr)
lot.cpp: In function 'int main()':
lot.cpp:23:11: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | while (i < s.size()) {
| ~~^~~~~~~~~~
lot.cpp:45:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | while (i < s.size()) {
| ~~^~~~~~~~~~
lot.cpp:55:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | else if (i < s.size() && s[start + j] != s[i]) {
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |