Submission #161656

# Submission time Handle Problem Language Result Execution time Memory
161656 2019-11-03T13:01:23 Z amoo_safar Lottery (CEOI18_lot) C++14
100 / 100
1118 ms 12544 KB
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl
using namespace std;

typedef int ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

ll MOD = (ll) 1e9 + 7;
const ll MAXN = (ll) 1e4 + 10;
const ll INF = (ll) (LONG_LONG_MAX - 3ll) / 2ll;
//const ll P = 104107;

inline ll mul(ll a, ll b){
	return (a * b) % MOD;
}

inline ll pw(ll b, ll p){
	if(p == 0) return 1;
	if(p & 1) return mul(b, pw(b, p - 1));
	return pw(mul(b,b), p / 2);
}

int a[MAXN];

vector<pll> V;

int ans[MAXN][102], del[MAXN][102];
int cnt[MAXN];
int dif[MAXN], ps[MAXN];
int num[110];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, l;
	cin >> n >> l;
	for(int i = 1; i <= n; i++) cin >> a[i];
	int Q, k;
	cin >> Q;
	for(int i = 1; i <= Q; i++){
		cin >> k;
		k = l - k;
		V.pb({k, i});
		for(int j = k; j <= l; j++) cnt[j] ++;
	}
	sort(all(V));
	for(int i = 1; i <= Q; i++){
		num[V[i - 1].S] = i;
	}
	
	int D;
	for(int len = 1; l + len <= n; len ++){
		for(int j = 1; j + len <= n; j++) dif[j] = (a[j] == a[j + len]);
		ps[0] = 0;
		for(int j = 1; j <= n; j++) ps[j] = dif[j] + ps[j - 1];
		for(int i = 1; i + l + len - 1 <= n; i++){
			D = ps[i + l - 1] - ps[i - 1];
			del[i][0] ++;
			del[i][cnt[D] + 1] --;
			del[i + len][0] ++;
			del[i + len][cnt[D] + 1] --;
		}
	}
	
	for(int i = 1; i <= n; i++){
		ans[i][0] = del[i][0];
		for(int j = 1; j <= Q; j++) ans[i][j] = del[i][j] + ans[i][j - 1];
	}
	for(int i = 1; i <= Q; i++){
		for(int j = 1; j + l - 1 <= n; j++) cout << ans[j][num[i]] << " \n"[j + l - 1== n];
	}
	
	return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 552 KB Output is correct
9 Correct 3 ms 632 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 3 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 552 KB Output is correct
9 Correct 3 ms 632 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 3 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 45 ms 1996 KB Output is correct
14 Correct 16 ms 1784 KB Output is correct
15 Correct 15 ms 1784 KB Output is correct
16 Correct 24 ms 2040 KB Output is correct
17 Correct 22 ms 1912 KB Output is correct
18 Correct 21 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 556 ms 8488 KB Output is correct
2 Correct 557 ms 8440 KB Output is correct
3 Correct 550 ms 8444 KB Output is correct
4 Correct 532 ms 8656 KB Output is correct
5 Correct 182 ms 6648 KB Output is correct
6 Correct 484 ms 8312 KB Output is correct
7 Correct 188 ms 6648 KB Output is correct
8 Correct 325 ms 7436 KB Output is correct
9 Correct 508 ms 8568 KB Output is correct
10 Correct 529 ms 8568 KB Output is correct
11 Correct 33 ms 2424 KB Output is correct
12 Correct 289 ms 7032 KB Output is correct
13 Correct 238 ms 6904 KB Output is correct
14 Correct 231 ms 6904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 556 ms 8488 KB Output is correct
2 Correct 557 ms 8440 KB Output is correct
3 Correct 550 ms 8444 KB Output is correct
4 Correct 532 ms 8656 KB Output is correct
5 Correct 182 ms 6648 KB Output is correct
6 Correct 484 ms 8312 KB Output is correct
7 Correct 188 ms 6648 KB Output is correct
8 Correct 325 ms 7436 KB Output is correct
9 Correct 508 ms 8568 KB Output is correct
10 Correct 529 ms 8568 KB Output is correct
11 Correct 33 ms 2424 KB Output is correct
12 Correct 289 ms 7032 KB Output is correct
13 Correct 238 ms 6904 KB Output is correct
14 Correct 231 ms 6904 KB Output is correct
15 Correct 533 ms 8396 KB Output is correct
16 Correct 458 ms 8208 KB Output is correct
17 Correct 551 ms 8696 KB Output is correct
18 Correct 533 ms 8568 KB Output is correct
19 Correct 541 ms 8568 KB Output is correct
20 Correct 545 ms 8524 KB Output is correct
21 Correct 544 ms 8568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 552 KB Output is correct
9 Correct 3 ms 632 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 3 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 45 ms 1996 KB Output is correct
14 Correct 16 ms 1784 KB Output is correct
15 Correct 15 ms 1784 KB Output is correct
16 Correct 24 ms 2040 KB Output is correct
17 Correct 22 ms 1912 KB Output is correct
18 Correct 21 ms 1912 KB Output is correct
19 Correct 556 ms 8488 KB Output is correct
20 Correct 557 ms 8440 KB Output is correct
21 Correct 550 ms 8444 KB Output is correct
22 Correct 532 ms 8656 KB Output is correct
23 Correct 182 ms 6648 KB Output is correct
24 Correct 484 ms 8312 KB Output is correct
25 Correct 188 ms 6648 KB Output is correct
26 Correct 325 ms 7436 KB Output is correct
27 Correct 508 ms 8568 KB Output is correct
28 Correct 529 ms 8568 KB Output is correct
29 Correct 33 ms 2424 KB Output is correct
30 Correct 289 ms 7032 KB Output is correct
31 Correct 238 ms 6904 KB Output is correct
32 Correct 231 ms 6904 KB Output is correct
33 Correct 533 ms 8396 KB Output is correct
34 Correct 458 ms 8208 KB Output is correct
35 Correct 551 ms 8696 KB Output is correct
36 Correct 533 ms 8568 KB Output is correct
37 Correct 541 ms 8568 KB Output is correct
38 Correct 545 ms 8524 KB Output is correct
39 Correct 544 ms 8568 KB Output is correct
40 Correct 899 ms 9220 KB Output is correct
41 Correct 29 ms 4984 KB Output is correct
42 Correct 878 ms 9336 KB Output is correct
43 Correct 522 ms 8824 KB Output is correct
44 Correct 716 ms 9012 KB Output is correct
45 Correct 1118 ms 12408 KB Output is correct
46 Correct 36 ms 5368 KB Output is correct
47 Correct 713 ms 12544 KB Output is correct
48 Correct 603 ms 10572 KB Output is correct
49 Correct 622 ms 11248 KB Output is correct