# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
617239 |
2022-08-01T09:55:14 Z |
erray |
Lottery (CEOI18_lot) |
C++17 |
|
801 ms |
8296 KB |
// 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 |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
29 ms |
392 KB |
Output is correct |
14 |
Correct |
14 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
340 KB |
Output is correct |
16 |
Correct |
7 ms |
552 KB |
Output is correct |
17 |
Correct |
6 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
354 ms |
500 KB |
Output is correct |
2 |
Correct |
268 ms |
492 KB |
Output is correct |
3 |
Correct |
103 ms |
496 KB |
Output is correct |
4 |
Correct |
52 ms |
468 KB |
Output is correct |
5 |
Correct |
174 ms |
476 KB |
Output is correct |
6 |
Correct |
46 ms |
504 KB |
Output is correct |
7 |
Correct |
501 ms |
476 KB |
Output is correct |
8 |
Correct |
619 ms |
488 KB |
Output is correct |
9 |
Correct |
109 ms |
496 KB |
Output is correct |
10 |
Correct |
76 ms |
496 KB |
Output is correct |
11 |
Correct |
17 ms |
372 KB |
Output is correct |
12 |
Correct |
80 ms |
468 KB |
Output is correct |
13 |
Correct |
82 ms |
468 KB |
Output is correct |
14 |
Correct |
114 ms |
480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
354 ms |
500 KB |
Output is correct |
2 |
Correct |
268 ms |
492 KB |
Output is correct |
3 |
Correct |
103 ms |
496 KB |
Output is correct |
4 |
Correct |
52 ms |
468 KB |
Output is correct |
5 |
Correct |
174 ms |
476 KB |
Output is correct |
6 |
Correct |
46 ms |
504 KB |
Output is correct |
7 |
Correct |
501 ms |
476 KB |
Output is correct |
8 |
Correct |
619 ms |
488 KB |
Output is correct |
9 |
Correct |
109 ms |
496 KB |
Output is correct |
10 |
Correct |
76 ms |
496 KB |
Output is correct |
11 |
Correct |
17 ms |
372 KB |
Output is correct |
12 |
Correct |
80 ms |
468 KB |
Output is correct |
13 |
Correct |
82 ms |
468 KB |
Output is correct |
14 |
Correct |
114 ms |
480 KB |
Output is correct |
15 |
Correct |
501 ms |
496 KB |
Output is correct |
16 |
Correct |
60 ms |
468 KB |
Output is correct |
17 |
Correct |
110 ms |
496 KB |
Output is correct |
18 |
Correct |
53 ms |
492 KB |
Output is correct |
19 |
Correct |
52 ms |
512 KB |
Output is correct |
20 |
Correct |
50 ms |
496 KB |
Output is correct |
21 |
Correct |
59 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
29 ms |
392 KB |
Output is correct |
14 |
Correct |
14 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
340 KB |
Output is correct |
16 |
Correct |
7 ms |
552 KB |
Output is correct |
17 |
Correct |
6 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
19 |
Correct |
354 ms |
500 KB |
Output is correct |
20 |
Correct |
268 ms |
492 KB |
Output is correct |
21 |
Correct |
103 ms |
496 KB |
Output is correct |
22 |
Correct |
52 ms |
468 KB |
Output is correct |
23 |
Correct |
174 ms |
476 KB |
Output is correct |
24 |
Correct |
46 ms |
504 KB |
Output is correct |
25 |
Correct |
501 ms |
476 KB |
Output is correct |
26 |
Correct |
619 ms |
488 KB |
Output is correct |
27 |
Correct |
109 ms |
496 KB |
Output is correct |
28 |
Correct |
76 ms |
496 KB |
Output is correct |
29 |
Correct |
17 ms |
372 KB |
Output is correct |
30 |
Correct |
80 ms |
468 KB |
Output is correct |
31 |
Correct |
82 ms |
468 KB |
Output is correct |
32 |
Correct |
114 ms |
480 KB |
Output is correct |
33 |
Correct |
501 ms |
496 KB |
Output is correct |
34 |
Correct |
60 ms |
468 KB |
Output is correct |
35 |
Correct |
110 ms |
496 KB |
Output is correct |
36 |
Correct |
53 ms |
492 KB |
Output is correct |
37 |
Correct |
52 ms |
512 KB |
Output is correct |
38 |
Correct |
50 ms |
496 KB |
Output is correct |
39 |
Correct |
59 ms |
492 KB |
Output is correct |
40 |
Correct |
688 ms |
1988 KB |
Output is correct |
41 |
Correct |
29 ms |
552 KB |
Output is correct |
42 |
Correct |
155 ms |
2012 KB |
Output is correct |
43 |
Correct |
67 ms |
1612 KB |
Output is correct |
44 |
Correct |
82 ms |
1716 KB |
Output is correct |
45 |
Correct |
801 ms |
8176 KB |
Output is correct |
46 |
Correct |
30 ms |
1100 KB |
Output is correct |
47 |
Correct |
638 ms |
8296 KB |
Output is correct |
48 |
Correct |
118 ms |
6252 KB |
Output is correct |
49 |
Correct |
113 ms |
6900 KB |
Output is correct |