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 lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
for (; l != r; ++l)
cout << *l << " \n"[l + 1 == r];
}
#ifdef Doludu
#define test(x...) abc("[" + string(#x) + "]", x);
#else
#define test(x...) void(0);
#endif
const int N = 2000;
int main () {
ios::sync_with_stdio(false);
cin.tie(0);
int n, len;
cin >> n >> len;
vector <int> v(n);
for (int i = 0; i < n; ++i)
cin >> v[i];
int q;
cin >> q;
vector <int> queries(q);
vector <vector <int>> ans(q, vector <int>(n - len + 1));
for (int i = 0; i < q; ++i)
cin >> queries[i];
vector <int> res;
for (int d = 1; len + d <= n; ++d) {
res.assign(n + 1, 0);
int bound = max(n - d - len + 1, 0);
for (int a = 0; a + d <= n; ++a) {
int b = a + d;
if (v[a] != v[b])
continue;
// x + i = a, y + i = b, a - len < st <= a
// y - x = b - a
// a - len + 1 <= st < a + 1
res[max(a - len + 1, 0)]++;
res[min(a + 1, bound)]--;
}
for (int i = 1; i <= n; ++i)
res[i] += res[i - 1];
for (int id = 0; id < q; ++id) {
for (int i = 0; i + d + len <= n; ++i) {
if (res[i] >= len - queries[id])
ans[id][i]++, ans[id][i + d]++;
}
}
}
for (int i = 0; i < q; ++i)
printv(all(ans[i]));
}
# | 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... |