This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// author: erray
#include <bits/stdc++.h>
using namespace std;
template<typename A, typename B> string to_string(pair<A, B> p);
template<typename A, typename B, typename C> string to_string(tuple<A, B, C> t);
template<typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> t);
string to_string(string s) {
return '"' + s + '"';
}
string to_string(char c) {
return string("'") + c + "'";
}
string to_string(const char* c) {
return to_string(string(c));
}
string to_string(bool b) {
return (b ? "true" : "false");
}
template<size_t T> string to_string(bitset<T> bs) {
return bs.to_string();
}
string to_string(vector<bool> v) {
string res = "{";
for (int i = 0; i < int(v.size()); ++i) {
if (i > 0) {
res += ", ";
}
res += to_string(v[i]);
}
res += "}";
return res;
}
template<typename T> string to_string(T v) {
string res = "{";
for (auto& e : v) {
if (int(res.size()) > 1) {
res += ", ";
}
res += to_string(e);
}
res += "}";
return res;
}
template<typename A, typename B> string to_string(pair<A, B> p) {
return '(' + to_string(p.first) + ", " + to_string(p.second) + ')';
}
template<typename A, typename B, typename C> string to_string(tuple<A, B, C> t) {
return '(' + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + '}';
}
template<typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> t) {
return '(' + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + '}';
}
void debug_out() {
cerr << endl;
}
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) void(37)
#endif
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N, L;
cin >> N >> L;
vector<int> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
vector<int> next(N, -1);
for (int i = N - 1; i >= 0; --i) {
for (int j = i + 1; j < N; ++j) {
if (A[i] == A[j]) {
next[i] = j;
break;
}
}
}
int Q;
cin >> Q;
vector<int> K(Q);
for (int i = 0; i < Q; ++i) {
cin >> K[i];
}
vector<int> ord(Q);
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int x, int y) {
return K[x] < K[y];
});
vector<valarray<int>> ans(Q, valarray<int>(N - L + 1));
//vector<vector<int>> l(L + 1);
vector<int> delta(N);
auto Modify = [&](int x, int d) {
int p = next[x];
while (p != -1) {
delta[p - x] += d;
p = next[p];
}
};
for (int i = 0; i < L - 1; ++i) {
Modify(i, +1);
}
for (int i = 0; i < N - L + 1; ++i) {
vector<vector<int>> l(L + 1);
Modify(i + L - 1, +1);
debug(i, delta);
//calculate the shit
for (int j = 1; i + j < N - L + 1; ++j) {
l[L - delta[j]].push_back(i + j);
}
int p = 0;
valarray<int> res(N - L + 1);
for (auto j : ord) {
int x = K[j];
while (p <= x) {
for (auto e : l[p]) {
res[e] += 1, res[i] += 1;
}
++p;
}
ans[j] += res;
}
/*
for (int j = 0; j <= L; ++j) {
l[j].clear();
vector<int>().swap(l[j]);
}
*/
Modify(i, -1);
}
for (int i = 0; i < Q; ++i) {
for (int j = 0; j < N - L + 1; ++j) {
cout << ans[i][j] << " \n"[j == N - L];
}
}
}
# | 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... |