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);
/*
map<int, vector<int>> vs;
for (int i = 0; i < N; ++i) {
vs[A[i]].push_back(i);
}
for (auto[foo, v] : vs) {
for (int i = 0; i < int(v.size()) - 1; ++i) {
next[v[i]] = v[i + 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<int> first(L + 1, -1);
for (int i = Q - 1; i >= 0; --i) {
first[K[ord[i]]] = ord[i];
}
for (int i = L; i > 0; --i) {
if (first[i - 1] == -1) {
first[i - 1] = first[i];
}
}
vector<valarray<int>> ans(Q, valarray<int>(N - 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) {
Modify(i + L - 1, +1);
for (int j = 1; i + j < N - L + 1; ++j) {
int x = L - delta[j];
if (first[x] != -1) {
ans[first[x]][i] += 1;
ans[first[x]][i + j] += 1;
}
}
Modify(i, -1);
}
for (int i = 0; i < Q - 1; ++i) {
ans[ord[i + 1]] += ans[ord[i]];
}
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... |