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 for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'
const int MXN = 1e4, MXQ = 100;
int freq[MXQ+1][MXN+2];
int main() {
#ifdef shiven
freopen("test.in", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, l; cin >> n >> l;
vi nums(n);
for_(i, 0, n) cin >> nums[i];
int q; cin >> q;
vector<ii> qrs(q);
for_(i, 0, q) {
cin >> qrs[i].first;
qrs[i].second = i;
}
sort(qrs.begin(), qrs.end());
for_(d, 1, n+1) {
vi temp(n);
for_(j, d, n) if (nums[j] != nums[j-d]) temp[j] += 1;
for_(i, d, n) temp[i] += temp[i-1];
for_(j, d, n-l+1) {
int dist = temp[j+l-1] - (j > 0 ? temp[j-1] : 0);
int idx = lower_bound(qrs.begin(), qrs.end(), (ii) {dist, -1}) - qrs.begin();
if (idx < q) {
freq[qrs[idx].second][j] += 1; freq[qrs[idx].second][j-d] += 1;
}
}
}
for_(i, 0, q) {
for_(j, 0, n-l+1) {
if (i > 0) freq[qrs[i].second][j] += freq[qrs[i-1].second][j];
cout << freq[qrs[i].second][j] << " ";
}
cout << endl;
}
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... |