답안 #246210

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246210 2020-07-08T11:07:19 Z tonowak Lottery (CEOI18_lot) C++14
100 / 100
1043 ms 8440 KB
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using LL = long long;    // Poland
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n) - 1)
template<class T> int size(T &&x) {
	return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
	out << '{';
	for(auto it = x.begin(); it != x.end(); ++it)
		out << *it << (it == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
	cerr << x << ";  ";
	dump(args...);
}
#ifdef DEBUG
  struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Nl(), cerr << ""
#else
# define debug(...) 0 && cerr
#endif
mt19937_64 rng(0);
int rd(int l, int r) {
	return uniform_int_distribution<int>(l, r)(rng);
}
// end of templates

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n, l;
	cin >> n >> l;
	vector<int> a(n);
	for(int &ai : a)
		cin >> ai;

	int q;
	cin >> q;
	vector<int> k(q);
	for(int &ki : k)
		cin >> ki;
	vector<vector<int>> answer(q, vector<int>(n - l + 1));
	
	vector<int> closest_qi(l + 1, -1);
	REP(i, q)
		closest_qi[k[i]] = i;

	for(int i = l - 1; i >= 0; --i)
		if(closest_qi[i] == -1)
			closest_qi[i] = closest_qi[i + 1];
	debug(k, closest_qi);

	auto register_diff = [&](int i, int j, int diff) {
		debug(i, j, diff);
		if(closest_qi[diff] == -1)
			return;
		++answer[closest_qi[diff]][i];
		++answer[closest_qi[diff]][j];
	};

	for(int delta = 1; delta + l - 1 < n; ++delta) {
		int diff = 0;
		REP(i, l)
			diff += bool(a[i] != a[i + delta]);
		register_diff(0, delta, diff);

		for(int left = 1; left + delta + l - 1 < n; ++left) {
			int right = left + delta;
			diff -= bool(a[left - 1] != a[right - 1]);
			diff += bool(a[left + l - 1] != a[right + l - 1]);
			register_diff(left, right, diff);
		}
	}
	debug(answer);

	for(int x = 1; x <= l; ++x)
		if(closest_qi[x] != closest_qi[x - 1] and closest_qi[x] != -1)
			REP(i, n - l + 1)
				answer[closest_qi[x]][i] += answer[closest_qi[x - 1]][i];
	REP(i, q)
		if(closest_qi[k[i]] != i)
			answer[i] = answer[closest_qi[k[i]]];

#if 1
	REP(i, q) {
		for(int ans : answer[i])
			cout << ans << ' ';
		cout << '\n';
	}
#else
	cout << "OK\n";
#endif
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 43 ms 504 KB Output is correct
14 Correct 25 ms 640 KB Output is correct
15 Correct 9 ms 512 KB Output is correct
16 Correct 14 ms 640 KB Output is correct
17 Correct 11 ms 640 KB Output is correct
18 Correct 12 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 292 ms 504 KB Output is correct
2 Correct 151 ms 512 KB Output is correct
3 Correct 133 ms 512 KB Output is correct
4 Correct 132 ms 632 KB Output is correct
5 Correct 64 ms 512 KB Output is correct
6 Correct 127 ms 632 KB Output is correct
7 Correct 243 ms 512 KB Output is correct
8 Correct 486 ms 632 KB Output is correct
9 Correct 165 ms 632 KB Output is correct
10 Correct 156 ms 632 KB Output is correct
11 Correct 11 ms 428 KB Output is correct
12 Correct 77 ms 512 KB Output is correct
13 Correct 70 ms 512 KB Output is correct
14 Correct 70 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 292 ms 504 KB Output is correct
2 Correct 151 ms 512 KB Output is correct
3 Correct 133 ms 512 KB Output is correct
4 Correct 132 ms 632 KB Output is correct
5 Correct 64 ms 512 KB Output is correct
6 Correct 127 ms 632 KB Output is correct
7 Correct 243 ms 512 KB Output is correct
8 Correct 486 ms 632 KB Output is correct
9 Correct 165 ms 632 KB Output is correct
10 Correct 156 ms 632 KB Output is correct
11 Correct 11 ms 428 KB Output is correct
12 Correct 77 ms 512 KB Output is correct
13 Correct 70 ms 512 KB Output is correct
14 Correct 70 ms 512 KB Output is correct
15 Correct 562 ms 632 KB Output is correct
16 Correct 126 ms 636 KB Output is correct
17 Correct 176 ms 632 KB Output is correct
18 Correct 131 ms 632 KB Output is correct
19 Correct 160 ms 632 KB Output is correct
20 Correct 132 ms 632 KB Output is correct
21 Correct 132 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 43 ms 504 KB Output is correct
14 Correct 25 ms 640 KB Output is correct
15 Correct 9 ms 512 KB Output is correct
16 Correct 14 ms 640 KB Output is correct
17 Correct 11 ms 640 KB Output is correct
18 Correct 12 ms 640 KB Output is correct
19 Correct 292 ms 504 KB Output is correct
20 Correct 151 ms 512 KB Output is correct
21 Correct 133 ms 512 KB Output is correct
22 Correct 132 ms 632 KB Output is correct
23 Correct 64 ms 512 KB Output is correct
24 Correct 127 ms 632 KB Output is correct
25 Correct 243 ms 512 KB Output is correct
26 Correct 486 ms 632 KB Output is correct
27 Correct 165 ms 632 KB Output is correct
28 Correct 156 ms 632 KB Output is correct
29 Correct 11 ms 428 KB Output is correct
30 Correct 77 ms 512 KB Output is correct
31 Correct 70 ms 512 KB Output is correct
32 Correct 70 ms 512 KB Output is correct
33 Correct 562 ms 632 KB Output is correct
34 Correct 126 ms 636 KB Output is correct
35 Correct 176 ms 632 KB Output is correct
36 Correct 131 ms 632 KB Output is correct
37 Correct 160 ms 632 KB Output is correct
38 Correct 132 ms 632 KB Output is correct
39 Correct 132 ms 600 KB Output is correct
40 Correct 957 ms 2028 KB Output is correct
41 Correct 17 ms 640 KB Output is correct
42 Correct 255 ms 2040 KB Output is correct
43 Correct 234 ms 1656 KB Output is correct
44 Correct 159 ms 1784 KB Output is correct
45 Correct 1043 ms 8184 KB Output is correct
46 Correct 24 ms 1272 KB Output is correct
47 Correct 1031 ms 8440 KB Output is correct
48 Correct 204 ms 6392 KB Output is correct
49 Correct 214 ms 7032 KB Output is correct