Submission #116450

# Submission time Handle Problem Language Result Execution time Memory
116450 2019-06-12T13:22:50 Z maruii Lottery (CEOI18_lot) C++14
100 / 100
380 ms 8988 KB
#include <bits/stdc++.h>
using namespace std;

int A[100001], ans[100][100001], idx[100];

int X[100001], B[100001];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int N, L; cin >> N >> L;
	for (int i = 1; i <= N; ++i) cin >> A[i];
	int Q; cin >> Q;
	pair<int, int> qry[Q];
	for (int i = 0; i < Q; ++i) {
		int x; cin >> x;
		qry[i] = {x, i};
	}

	sort(qry, qry + Q);
	memset(B, -1, sizeof(B));
	for (int i = 0; i < Q; ++i) {
		if (!i || qry[i-1].first != qry[i].first) B[qry[i].first] = i;
		idx[qry[i].second] = i;
	}
	for (int i = L; i; --i)
		if (B[i-1] == -1) B[i-1] = B[i];

	for (int d = 1; d <= N - L; ++d) {
		for (int i = 1; i + d <= N; ++i) {
			X[i] = X[i-1] + (A[i] != A[i + d]);
		}
		for (int i = 1; i + d + L - 1 <= N; ++i) {
			int t = B[X[i + L - 1] - X[i - 1]];
			if (t == -1) continue;
			++ans[t][i];
			++ans[t][i + d];
		}
	}

	for (int i = 1; i < Q; ++i) {
		for (int j = 1; j <= N - L + 1; ++j) {
			if (qry[i].first != qry[i-1].first) ans[i][j] += ans[i-1][j];
			else ans[i][j] = ans[i-1][j];
		}
	}

	for (int i = 0; i < Q; ++i) {
		for (int j = 1; j <= N - L + 1; ++j) cout << ans[idx[i]][j] << ' ';
		cout << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 768 KB Output is correct
2 Correct 2 ms 768 KB Output is correct
3 Correct 2 ms 768 KB Output is correct
4 Correct 2 ms 768 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 2 ms 768 KB Output is correct
7 Correct 2 ms 740 KB Output is correct
8 Correct 3 ms 896 KB Output is correct
9 Correct 2 ms 896 KB Output is correct
10 Correct 3 ms 896 KB Output is correct
11 Correct 3 ms 896 KB Output is correct
12 Correct 3 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 768 KB Output is correct
2 Correct 2 ms 768 KB Output is correct
3 Correct 2 ms 768 KB Output is correct
4 Correct 2 ms 768 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 2 ms 768 KB Output is correct
7 Correct 2 ms 740 KB Output is correct
8 Correct 3 ms 896 KB Output is correct
9 Correct 2 ms 896 KB Output is correct
10 Correct 3 ms 896 KB Output is correct
11 Correct 3 ms 896 KB Output is correct
12 Correct 3 ms 896 KB Output is correct
13 Correct 13 ms 896 KB Output is correct
14 Correct 11 ms 1024 KB Output is correct
15 Correct 9 ms 868 KB Output is correct
16 Correct 11 ms 1024 KB Output is correct
17 Correct 12 ms 1008 KB Output is correct
18 Correct 11 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 253 ms 916 KB Output is correct
2 Correct 183 ms 912 KB Output is correct
3 Correct 177 ms 896 KB Output is correct
4 Correct 174 ms 964 KB Output is correct
5 Correct 106 ms 896 KB Output is correct
6 Correct 164 ms 964 KB Output is correct
7 Correct 124 ms 956 KB Output is correct
8 Correct 173 ms 968 KB Output is correct
9 Correct 175 ms 964 KB Output is correct
10 Correct 172 ms 984 KB Output is correct
11 Correct 15 ms 740 KB Output is correct
12 Correct 118 ms 924 KB Output is correct
13 Correct 120 ms 936 KB Output is correct
14 Correct 122 ms 932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 253 ms 916 KB Output is correct
2 Correct 183 ms 912 KB Output is correct
3 Correct 177 ms 896 KB Output is correct
4 Correct 174 ms 964 KB Output is correct
5 Correct 106 ms 896 KB Output is correct
6 Correct 164 ms 964 KB Output is correct
7 Correct 124 ms 956 KB Output is correct
8 Correct 173 ms 968 KB Output is correct
9 Correct 175 ms 964 KB Output is correct
10 Correct 172 ms 984 KB Output is correct
11 Correct 15 ms 740 KB Output is correct
12 Correct 118 ms 924 KB Output is correct
13 Correct 120 ms 936 KB Output is correct
14 Correct 122 ms 932 KB Output is correct
15 Correct 216 ms 912 KB Output is correct
16 Correct 161 ms 980 KB Output is correct
17 Correct 180 ms 972 KB Output is correct
18 Correct 170 ms 896 KB Output is correct
19 Correct 170 ms 964 KB Output is correct
20 Correct 172 ms 968 KB Output is correct
21 Correct 173 ms 968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 768 KB Output is correct
2 Correct 2 ms 768 KB Output is correct
3 Correct 2 ms 768 KB Output is correct
4 Correct 2 ms 768 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 2 ms 768 KB Output is correct
7 Correct 2 ms 740 KB Output is correct
8 Correct 3 ms 896 KB Output is correct
9 Correct 2 ms 896 KB Output is correct
10 Correct 3 ms 896 KB Output is correct
11 Correct 3 ms 896 KB Output is correct
12 Correct 3 ms 896 KB Output is correct
13 Correct 13 ms 896 KB Output is correct
14 Correct 11 ms 1024 KB Output is correct
15 Correct 9 ms 868 KB Output is correct
16 Correct 11 ms 1024 KB Output is correct
17 Correct 12 ms 1008 KB Output is correct
18 Correct 11 ms 1024 KB Output is correct
19 Correct 253 ms 916 KB Output is correct
20 Correct 183 ms 912 KB Output is correct
21 Correct 177 ms 896 KB Output is correct
22 Correct 174 ms 964 KB Output is correct
23 Correct 106 ms 896 KB Output is correct
24 Correct 164 ms 964 KB Output is correct
25 Correct 124 ms 956 KB Output is correct
26 Correct 173 ms 968 KB Output is correct
27 Correct 175 ms 964 KB Output is correct
28 Correct 172 ms 984 KB Output is correct
29 Correct 15 ms 740 KB Output is correct
30 Correct 118 ms 924 KB Output is correct
31 Correct 120 ms 936 KB Output is correct
32 Correct 122 ms 932 KB Output is correct
33 Correct 216 ms 912 KB Output is correct
34 Correct 161 ms 980 KB Output is correct
35 Correct 180 ms 972 KB Output is correct
36 Correct 170 ms 896 KB Output is correct
37 Correct 170 ms 964 KB Output is correct
38 Correct 172 ms 968 KB Output is correct
39 Correct 173 ms 968 KB Output is correct
40 Correct 265 ms 2432 KB Output is correct
41 Correct 29 ms 1100 KB Output is correct
42 Correct 193 ms 2508 KB Output is correct
43 Correct 178 ms 2192 KB Output is correct
44 Correct 179 ms 2168 KB Output is correct
45 Correct 380 ms 8916 KB Output is correct
46 Correct 34 ms 2168 KB Output is correct
47 Correct 317 ms 8988 KB Output is correct
48 Correct 226 ms 7268 KB Output is correct
49 Correct 227 ms 7800 KB Output is correct