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;
i++;
}
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 (j < l && (s[i] == s[start + j])) {
if (s[i] != s[start + j])cur++;
i++;
j++;
}
else {
cur--;
while (j) {
if (s[start + j - 1] == s[i])break;
j = p[j - 1];
}
i++;
}
if (j == l) {
res[start]++;
}
}
}
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:46: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]
46 | while (i < s.size()) {
| ~~^~~~~~~~~~
# | 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... |