Submission #523131

# Submission time Handle Problem Language Result Execution time Memory
523131 2022-02-07T06:08:12 Z valerikk Lottery (CEOI18_lot) C++17
100 / 100
921 ms 8632 KB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	ios::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];
	}
	
	int q;
	cin >> q;
	vector<int> k(q);
	for (int i = 0; i < q; ++i) {
		cin >> k[i];
	}

	vector<int> ord(q);
	for (int i = 0; i < q; ++i) {
		ord[i] = i;
	}
	sort(ord.begin(), ord.end(), [&](int i, int j) {
		return k[i] < k[j];
	});

	vector<int> first(l + 1, q);
	for (int i = 0; i < q; ++i) {
		first[k[ord[i]]] = min(first[k[ord[i]]], i);
	}
	for (int i = l - 1; i >= 0; --i) {
		first[i] = min(first[i], first[i + 1]);
	}

	vector ans(n, vector<int>(q + 1, 0));
	for (int d = 1; d <= n - l; ++d) {
		vector<int> cnt(n + 1, 0);
		for (int i = 0; i + d < n; ++i) {
			if (a[i] != a[i + d]) {
				++cnt[max(0, i - l + 1)];
				--cnt[i + 1];
			}
		}
		for (int i = 0; i + d + l <= n; ++i) {
			++ans[i][first[cnt[i]]];
			++ans[i + d][first[cnt[i]]];
			cnt[i + 1] += cnt[i];
		}
	}

	for (int i = 0; i < n - l + 1; ++i) {
		for (int j = 0; j < q; ++j) {
			ans[i][j + 1] += ans[i][j];
		}
	}

	vector<int> rev(q);
	for (int i = 0; i < q; ++i) {
		rev[ord[i]] = i;
	}

	for (int i = 0; i < q; ++i) {
		for (int j = 0; j < n - l + 1; ++j) {
			cout << ans[j][rev[i]] << " ";
		}
		cout << "\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 27 ms 440 KB Output is correct
14 Correct 18 ms 584 KB Output is correct
15 Correct 16 ms 460 KB Output is correct
16 Correct 25 ms 584 KB Output is correct
17 Correct 23 ms 588 KB Output is correct
18 Correct 24 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 841 ms 952 KB Output is correct
2 Correct 838 ms 948 KB Output is correct
3 Correct 671 ms 972 KB Output is correct
4 Correct 625 ms 1032 KB Output is correct
5 Correct 211 ms 1048 KB Output is correct
6 Correct 557 ms 1032 KB Output is correct
7 Correct 180 ms 1064 KB Output is correct
8 Correct 321 ms 1040 KB Output is correct
9 Correct 586 ms 1036 KB Output is correct
10 Correct 601 ms 1028 KB Output is correct
11 Correct 30 ms 460 KB Output is correct
12 Correct 352 ms 960 KB Output is correct
13 Correct 274 ms 1052 KB Output is correct
14 Correct 273 ms 1060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 841 ms 952 KB Output is correct
2 Correct 838 ms 948 KB Output is correct
3 Correct 671 ms 972 KB Output is correct
4 Correct 625 ms 1032 KB Output is correct
5 Correct 211 ms 1048 KB Output is correct
6 Correct 557 ms 1032 KB Output is correct
7 Correct 180 ms 1064 KB Output is correct
8 Correct 321 ms 1040 KB Output is correct
9 Correct 586 ms 1036 KB Output is correct
10 Correct 601 ms 1028 KB Output is correct
11 Correct 30 ms 460 KB Output is correct
12 Correct 352 ms 960 KB Output is correct
13 Correct 274 ms 1052 KB Output is correct
14 Correct 273 ms 1060 KB Output is correct
15 Correct 652 ms 972 KB Output is correct
16 Correct 532 ms 1036 KB Output is correct
17 Correct 645 ms 1156 KB Output is correct
18 Correct 641 ms 1036 KB Output is correct
19 Correct 637 ms 1044 KB Output is correct
20 Correct 626 ms 1044 KB Output is correct
21 Correct 614 ms 1032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 27 ms 440 KB Output is correct
14 Correct 18 ms 584 KB Output is correct
15 Correct 16 ms 460 KB Output is correct
16 Correct 25 ms 584 KB Output is correct
17 Correct 23 ms 588 KB Output is correct
18 Correct 24 ms 588 KB Output is correct
19 Correct 841 ms 952 KB Output is correct
20 Correct 838 ms 948 KB Output is correct
21 Correct 671 ms 972 KB Output is correct
22 Correct 625 ms 1032 KB Output is correct
23 Correct 211 ms 1048 KB Output is correct
24 Correct 557 ms 1032 KB Output is correct
25 Correct 180 ms 1064 KB Output is correct
26 Correct 321 ms 1040 KB Output is correct
27 Correct 586 ms 1036 KB Output is correct
28 Correct 601 ms 1028 KB Output is correct
29 Correct 30 ms 460 KB Output is correct
30 Correct 352 ms 960 KB Output is correct
31 Correct 274 ms 1052 KB Output is correct
32 Correct 273 ms 1060 KB Output is correct
33 Correct 652 ms 972 KB Output is correct
34 Correct 532 ms 1036 KB Output is correct
35 Correct 645 ms 1156 KB Output is correct
36 Correct 641 ms 1036 KB Output is correct
37 Correct 637 ms 1044 KB Output is correct
38 Correct 626 ms 1044 KB Output is correct
39 Correct 614 ms 1032 KB Output is correct
40 Correct 860 ms 2348 KB Output is correct
41 Correct 36 ms 1732 KB Output is correct
42 Correct 658 ms 2356 KB Output is correct
43 Correct 603 ms 2044 KB Output is correct
44 Correct 594 ms 2168 KB Output is correct
45 Correct 921 ms 8632 KB Output is correct
46 Correct 36 ms 5060 KB Output is correct
47 Correct 691 ms 8624 KB Output is correct
48 Correct 659 ms 6808 KB Output is correct
49 Correct 656 ms 7492 KB Output is correct