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;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = b - 1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define umap unordered_map
#define uset unordered_set
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
const int INF = 1000000007;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
ushort n, l, q, mismatch[10003], groups, queryval[101];
int arr[10003];
cin >> n >> l;
groups = n - l + 1;
rep(i, 0, n) cin >> arr[i];
umap<ushort, ushort> diffs[10003];
cin >> q;
vector<ushort> queries;
queries.pb(l + 1);
rep(i, 0, q) {
cin >> queryval[i];
queries.pb(queryval[i]);
}
sort(all(queries));
memset(mismatch, 0, sizeof(mismatch));
rep(i, 0, l) rep(j, i + 1, groups + i) if (arr[i] != arr[j])++ mismatch[j - i];
rep(i, 0, groups) {
rep(j, 1, groups - i) {
int val = *lower_bound(all(queries), mismatch[j]);
++diffs[i][val];
++diffs[j + i][val];
}
rep(j, i + 1, min(int(n), groups + i)) if (arr[i] != arr[j])-- mismatch[j - i];
rep(j, i + l + 1, n) if (arr[i + l] != arr[j])++ mismatch[j - i - l];
}
rep(i, 0, q) {
rep(j, 0, groups) {
int ans = 0;
trav(item, diffs[j]) if (item.first <= queryval[i]) ans += item.second;
cout << ans << ' ';
}
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... |