Submission #167831

# Submission time Handle Problem Language Result Execution time Memory
167831 2019-12-10T10:00:42 Z kostia244 Lottery (CEOI18_lot) C++17
65 / 100
133 ms 16600 KB
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using vi = vector<int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
short cmp[2020][2020], dp[2020][2020];
int n, l, q;
vi a;
const int mod = 1e9 + 9;
const int base = 11000 + rng()%10000;
ll pw[10100];
map<int, int> hsh;
void solve2() {
	ll hash = 0;
	for(int i = 0; i < n; i++) {
		hash = (hash*base + a[i])%mod;
		if(i-l>=0) {
			hash = hash-(pw[l]*a[i-l])%mod;
			if(hash<0) hash+=mod;
		}
		if(i-l+1>=0)
			hsh[hash]++;
	}
	hash = 0;
	for(int i = 0; i < n; i++) {
		hash = (hash*base + a[i])%mod;
		if(i-l>=0) {
			hash = hash-(pw[l]*a[i-l])%mod;
			if(hash<0) hash+=mod;
		}
		if(i-l+1>=0)
			cout << hsh[hash]-1 << " ";
	}
	exit(0);
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	pw[0] = 1;
	for(int i = 1; i < 10100; i++)
		pw[i] = (pw[i-1]*1ll*base)%mod;
	cin >> n >> l;
	a.resize(n);
	for(auto &i : a)cin >> i;
	if(n>2000) solve2();
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			dp[i][j] = a[i]!=a[j];
	int cmped = 0;
	for(int k = 0; (1<<k) <= l; k++) {
		if((1<<k)&l) {
			for(int i = 0; i < n; i++) {
				for(int j = i+1; j < n; j++) {
					cmp[i][j] += dp[i+cmped][j+cmped];
				}
			}
			cmped += (1<<k);
		}
		for(int i = 0; i+(1<<k) < n; i++) {
			for(int j = i+1; j+(1<<k) < n; j++) {
				dp[i][j] += dp[i+(1<<k)][j+(1<<k)];
			}
		}
	}
	int q, z;
	cin >> q;
	int ans[10010];
	while(q--) {
		cin >> z;
		if(q==0&&z==0) solve2();
		memset(ans, 0, sizeof ans);
		for(int i = 0; i+l-1 < n; i++) {
			for(int j = i+1; j+l-1 < n; j++)
				ans[i] += cmp[i][j]<=z, ans[j]+=cmp[i][j]<=z;
			cout << ans[i] << ' ';
		}
		cout << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 3 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 3 ms 1276 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 1272 KB Output is correct
8 Correct 5 ms 2808 KB Output is correct
9 Correct 5 ms 2808 KB Output is correct
10 Correct 7 ms 2808 KB Output is correct
11 Correct 7 ms 2808 KB Output is correct
12 Correct 7 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 3 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 3 ms 1276 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 1272 KB Output is correct
8 Correct 5 ms 2808 KB Output is correct
9 Correct 5 ms 2808 KB Output is correct
10 Correct 7 ms 2808 KB Output is correct
11 Correct 7 ms 2808 KB Output is correct
12 Correct 7 ms 2808 KB Output is correct
13 Correct 54 ms 16348 KB Output is correct
14 Correct 97 ms 16600 KB Output is correct
15 Correct 73 ms 16248 KB Output is correct
16 Correct 133 ms 16396 KB Output is correct
17 Correct 122 ms 16376 KB Output is correct
18 Correct 121 ms 16404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 4 ms 672 KB Output is correct
3 Correct 6 ms 632 KB Output is correct
4 Correct 7 ms 804 KB Output is correct
5 Correct 6 ms 860 KB Output is correct
6 Correct 8 ms 1016 KB Output is correct
7 Correct 4 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 636 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 7 ms 888 KB Output is correct
13 Correct 7 ms 888 KB Output is correct
14 Correct 7 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 4 ms 672 KB Output is correct
3 Correct 6 ms 632 KB Output is correct
4 Correct 7 ms 804 KB Output is correct
5 Correct 6 ms 860 KB Output is correct
6 Correct 8 ms 1016 KB Output is correct
7 Correct 4 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 636 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 7 ms 888 KB Output is correct
13 Correct 7 ms 888 KB Output is correct
14 Correct 7 ms 888 KB Output is correct
15 Incorrect 8 ms 1016 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 3 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 3 ms 1276 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 1272 KB Output is correct
8 Correct 5 ms 2808 KB Output is correct
9 Correct 5 ms 2808 KB Output is correct
10 Correct 7 ms 2808 KB Output is correct
11 Correct 7 ms 2808 KB Output is correct
12 Correct 7 ms 2808 KB Output is correct
13 Correct 54 ms 16348 KB Output is correct
14 Correct 97 ms 16600 KB Output is correct
15 Correct 73 ms 16248 KB Output is correct
16 Correct 133 ms 16396 KB Output is correct
17 Correct 122 ms 16376 KB Output is correct
18 Correct 121 ms 16404 KB Output is correct
19 Correct 4 ms 504 KB Output is correct
20 Correct 4 ms 672 KB Output is correct
21 Correct 6 ms 632 KB Output is correct
22 Correct 7 ms 804 KB Output is correct
23 Correct 6 ms 860 KB Output is correct
24 Correct 8 ms 1016 KB Output is correct
25 Correct 4 ms 632 KB Output is correct
26 Correct 5 ms 632 KB Output is correct
27 Correct 5 ms 632 KB Output is correct
28 Correct 5 ms 636 KB Output is correct
29 Correct 3 ms 604 KB Output is correct
30 Correct 7 ms 888 KB Output is correct
31 Correct 7 ms 888 KB Output is correct
32 Correct 7 ms 888 KB Output is correct
33 Incorrect 8 ms 1016 KB Output isn't correct
34 Halted 0 ms 0 KB -