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>
using namespace std;
const int mod = 1e9 + 7;
const int base = 727;
int score[2005][2005];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, l;
cin >> n >> l;
int a[n];
for (int i = 0; i < n; i ++)
cin >> a[i];
if (n <= 2000){
memset(score, 0, sizeof score);
for (int i = 0; i + l <= n; i ++){
for (int j = i + 1; j + l <= n; j ++)
for (int k = 0; k < l; k ++)
score[i][j] += (a[i + k] != a[j + k]);
for (int j = i + 1; j + l <= n; j ++)
score[j][i] = score[i][j];
}
for (int i = 0; i + l <= n; i ++)
sort(score[i], score[i] + n - l + 1);
int q;
cin >> q;
while (q--){
int k;
cin >> k;
for (int i = 0; i + l <= n; i ++){
int ub = upper_bound(score[i], score[i] + n - l + 1, k) - score[i];
cout << ub - 1 << " ";
}
cout << '\n';
}
return 0;
}
int Hash[n - l + 1];
for (int i=0; i+l<=n; i++){
int hsh = 0;
for (int j=0; j<l; j++)
hsh = ((1ll * hsh * base) + a[i + j]) % mod;
Hash[i] = hsh;
}
int q;
cin >> q;
while (q--){
int k;
cin >> k;
for (int i = 0; i + l <= n; i ++){
int ans = -1;
for (int j = 0; j + l <= n; j ++)
ans += (Hash[i] == Hash[j]);
cout << ans << " ";
}
cout << endl;
}
}
# | 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... |