이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 10004;
const int b = (int) 1e9 + 7;
const int mod = (int) 1e9 + 9;
int n, l, a[N], q, pb[N], h[N];
vector<int> v[N];
inline int get(int ql, int qr) {
return pb[n - ql] * 1LL * (h[qr + 1] - h[ql] + mod) % mod;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> l;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
cin >> q;
if (q == 1) {
int k;
cin >> k;
if (k == 0) {
map<int, int> mp;
pb[0] = 1;
for (int i = 1; i <= n; i++) {
pb[i] = pb[i - 1] * 1LL * b % mod;
}
for (int i = 0; i < n; i++) {
h[i + 1] = (pb[i] * 1LL * a[i] % mod + h[i]) % mod;
}
for (int i = 0; i + l <= n; i++) {
mp[get(i, i + l - 1)] += 1;
}
for (int i = 0; i + l <= n; i++) {
if (i > 0) {
cout << " ";
}
cout << mp[get(i, i + l - 1)] - 1;
}
cout << '\n';
} else {
for (int i = 0; i + l <= n; i++) {
for (int j = i + 1; j + l <= n; j++) {
if (j == i) continue;
int c = 0;
for (int kk = 0; kk < l; kk++) {
c += (a[i + kk] != a[j + kk]);
}
v[i].push_back(c);
v[j].push_back(c);
}
}
for (int i = 0; i + l <= n; i++) {
sort(v[i].begin(), v[i].end());
}
for (int i = 0; i + l <= n; i++) {
if (i > 0) {
cout << " ";
}
cout << upper_bound(v[i].begin(), v[i].end(), k) - v[i].begin();
}
cout << '\n';
}
return 0;
}
for (int i = 0; i + l <= n; i++) {
for (int j = i + 1; j + l <= n; j++) {
if (j == i) continue;
int c = 0;
for (int k = 0; k < l; k++) {
c += (a[i + k] != a[j + k]);
}
v[i].push_back(c);
v[j].push_back(c);
}
}
for (int i = 0; i + l <= n; i++) {
sort(v[i].begin(), v[i].end());
}
while (q--) {
int k;
cin >> k;
for (int i = 0; i + l <= n; i++) {
if (i > 0) {
cout << " ";
}
cout << upper_bound(v[i].begin(), v[i].end(), k) - v[i].begin();
}
cout << '\n';
}
return 0;
}
# | 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... |