답안 #827420

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
827420 2023-08-16T12:57:52 Z MadokaMagicaFan Lottery (CEOI18_lot) C++14
80 / 100
2691 ms 9368 KB
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define pb push_back
#define sz(v) ((int)v.size())

const ll inf = 1e16;
const int N = 10000;
int n, l, q;

vector<int> nm, v, ks;
vector<array<int,100>> ans;
int j[N], lst[N], e[N];
int bs(int x) {
	int l, r, m;
	l = 0;
	r = sz(nm);
	while (l < r) {
		m = (l+r)/2;
		if (nm[m] <= x)
			l = m+1;
		else
			r = m;
	}
	return l - 1;
}
int bs2(int x) {
	int l, r, m;
	l = 0;
	r = sz(ks);
	while (l < r) {
		m = (l+r)/2;
		if (ks[m] <= x)
			l = m+1;
		else
			r = m;
	}
	return l;
}

void _add(int x) {
	if (j[x] == 0) return;
	int d = x;
	do {
		d -= j[d];
		++e[x-d];
	} while (j[d]);
}

void _rem(int x) {
	if (j[x] == 0) return;
	int d = x;
	do {
		d -= j[d];
		--e[x-d];
	} while (j[d]);
}

void solve() {
	int u;
	for (int i = 0; i < n; ++i) {
		j[i] = 0; lst[i] = -1; e[i] = 0;
	}

	for (int i = 0; i < n; ++i) {
		if (lst[v[i]] != -1)
			j[i] = i - lst[v[i]];
		lst[v[i]] = i;
	}
	
	for (int i = 0; i < l; ++i)
		_add(i);

	for (int i = 1; i + l - 1 < n; ++i) {
		_add(i+l-1); _rem(i-1);
		for (int j = 1; j <= i; ++j) {
			u = bs2(e[j]);
			if (u) ans[i][u-1]++;
		}
	}
}



int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> l;
	v.assign(n, 0);
	ans.resize(n-l+1);
	for (int i = 0; i < n; ++i) cin >> v[i];
	for (int i = 0; i < n - l + 1; ++i)
		for (int j = 0; j < 100; ++j) ans[i][j] = 0;
	nm = v; sort(nm.begin(), nm.end()); nm.erase(unique(nm.begin(), nm.end()), nm.end());
	for (int i = 0; i < n; ++i) v[i] = bs(v[i]);
	cin >> q;
	vector<int> qq(q);
	for (int i = 0; i < q; ++i)
		cin>>qq[i];
	for (int i = 0; i < q; ++i)
		ks.pb(l - qq[i]);
	sort(ks.begin(), ks.end()); ks.erase(unique(ks.begin(), ks.end()), ks.end());

	solve();
	reverse(v.begin(), v.end());
	reverse(ans.begin(), ans.end());
	solve();
	reverse(ans.begin(), ans.end());
	for (int i = sz(ks)-1; i >= 0; --i)
		for (int j = 0; j < n - l + 1; ++j)
			ans[j][i] += ans[j][i+1];

	for (int i = 0; i < q; ++i) {
		for (int j = 0; j < n - l + 1; ++j)
			cout << ans[j][bs2(l-qq[i])-1] << (j == n-l ? '\n' : ' ');
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 27 ms 1164 KB Output is correct
14 Correct 12 ms 852 KB Output is correct
15 Correct 7 ms 852 KB Output is correct
16 Correct 18 ms 1092 KB Output is correct
17 Correct 13 ms 1040 KB Output is correct
18 Correct 13 ms 1040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 483 ms 4436 KB Output is correct
2 Correct 403 ms 4436 KB Output is correct
3 Correct 198 ms 4436 KB Output is correct
4 Correct 128 ms 4364 KB Output is correct
5 Correct 178 ms 2472 KB Output is correct
6 Correct 113 ms 4168 KB Output is correct
7 Correct 345 ms 2468 KB Output is correct
8 Correct 469 ms 3256 KB Output is correct
9 Correct 165 ms 4312 KB Output is correct
10 Correct 155 ms 4348 KB Output is correct
11 Correct 18 ms 1108 KB Output is correct
12 Correct 122 ms 3232 KB Output is correct
13 Correct 93 ms 2824 KB Output is correct
14 Correct 127 ms 2828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 483 ms 4436 KB Output is correct
2 Correct 403 ms 4436 KB Output is correct
3 Correct 198 ms 4436 KB Output is correct
4 Correct 128 ms 4364 KB Output is correct
5 Correct 178 ms 2472 KB Output is correct
6 Correct 113 ms 4168 KB Output is correct
7 Correct 345 ms 2468 KB Output is correct
8 Correct 469 ms 3256 KB Output is correct
9 Correct 165 ms 4312 KB Output is correct
10 Correct 155 ms 4348 KB Output is correct
11 Correct 18 ms 1108 KB Output is correct
12 Correct 122 ms 3232 KB Output is correct
13 Correct 93 ms 2824 KB Output is correct
14 Correct 127 ms 2828 KB Output is correct
15 Correct 556 ms 4308 KB Output is correct
16 Correct 129 ms 4052 KB Output is correct
17 Correct 235 ms 4436 KB Output is correct
18 Correct 126 ms 4404 KB Output is correct
19 Correct 128 ms 4388 KB Output is correct
20 Correct 126 ms 4392 KB Output is correct
21 Correct 128 ms 4388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 27 ms 1164 KB Output is correct
14 Correct 12 ms 852 KB Output is correct
15 Correct 7 ms 852 KB Output is correct
16 Correct 18 ms 1092 KB Output is correct
17 Correct 13 ms 1040 KB Output is correct
18 Correct 13 ms 1040 KB Output is correct
19 Correct 483 ms 4436 KB Output is correct
20 Correct 403 ms 4436 KB Output is correct
21 Correct 198 ms 4436 KB Output is correct
22 Correct 128 ms 4364 KB Output is correct
23 Correct 178 ms 2472 KB Output is correct
24 Correct 113 ms 4168 KB Output is correct
25 Correct 345 ms 2468 KB Output is correct
26 Correct 469 ms 3256 KB Output is correct
27 Correct 165 ms 4312 KB Output is correct
28 Correct 155 ms 4348 KB Output is correct
29 Correct 18 ms 1108 KB Output is correct
30 Correct 122 ms 3232 KB Output is correct
31 Correct 93 ms 2824 KB Output is correct
32 Correct 127 ms 2828 KB Output is correct
33 Correct 556 ms 4308 KB Output is correct
34 Correct 129 ms 4052 KB Output is correct
35 Correct 235 ms 4436 KB Output is correct
36 Correct 126 ms 4404 KB Output is correct
37 Correct 128 ms 4388 KB Output is correct
38 Correct 126 ms 4392 KB Output is correct
39 Correct 128 ms 4388 KB Output is correct
40 Correct 1459 ms 5152 KB Output is correct
41 Correct 30 ms 924 KB Output is correct
42 Correct 481 ms 5152 KB Output is correct
43 Correct 347 ms 4640 KB Output is correct
44 Correct 338 ms 4768 KB Output is correct
45 Correct 2691 ms 8224 KB Output is correct
46 Correct 38 ms 1176 KB Output is correct
47 Incorrect 768 ms 9368 KB Output isn't correct
48 Halted 0 ms 0 KB -