This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define arr array
#define vct vector
#define pii pair<int, int>
#define mpii make_pair
const int MX_N = 1e4 + 5, MX_Q = 1e2 + 5;
int n, l;
arr<int, MX_N> vl;
int q;
arr<pii, MX_Q> qry; // {value, index}
arr<int, MX_Q> indx;
arr<arr<int, MX_N>, 2> sm;
arr<arr<int, MX_Q>, MX_N> ans;
void cmp() {
for (int i = n; i >= 1; i--) {
int prt = i % 2, opp_prt = (i + 1) % 2;
for (int j = 1; j <= n; j++) sm[prt][j] = (vl[i] == vl[j]) + sm[opp_prt][j + 1];
for (int j = 1; j <= n - l + 1; j++) {
if (j == i) continue;
int k = lower_bound(qry.begin() + 1, qry.begin() + q + 1, mpii(l - sm[prt][j], -1)) - qry.begin();
ans[i][k]++;
}
for (int j = 1; j <= q; j++) ans[i][j] = ans[i][j] + ans[i][j - 1];
for (int j = 1; j <= n; j++) {
int nw_i = i + l - 1, nw_j = j + l - 1;
if (max(nw_i, nw_j) > n) continue;
sm[prt][j] -= (vl[nw_i] == vl[nw_j]);
}
}
}
signed main() {
// freopen("lttry.in", "r", stdin);
cin >> n >> l;
for (int i = 1; i <= n; i++) cin >> vl[i];
cin >> q;
for (int i = 1; i <= q; i++) { cin >> qry[i].first; qry[i].second = i; };
sort(qry.begin() + 1, qry.begin() + q + 1);
for (int i = 1; i <= q; i++) indx[qry[i].second] = i;
cmp();
for (int i = 1; i <= q; i++) {
for (int j = 1; j <= n - l + 1; j++) cout << ans[j][indx[i]] << " ";
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... |