Submission #259984

# Submission time Handle Problem Language Result Execution time Memory
259984 2020-08-08T21:35:42 Z Kenzo_1114 Lottery (CEOI18_lot) C++17
100 / 100
611 ms 8312 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 10010;
const int MAXQ = 110;

int N, L, Q, q[MAXN], a[MAXN], ans[MAXQ][MAXN], K[MAXN]; 

int main ()
{
	scanf("%d %d", &N, &L);

	for(int i = 1; i <= N; i++)	scanf("%d", &a[i]);

	scanf("%d", &Q);
	
	vector<pair<int, int> > qry;
	for(int i = 0, k; i < Q; i++)
	{
		scanf("%d", &k);
		qry.push_back(make_pair(k, i));
	}

	sort(qry.begin(), qry.end());

	for(int i = 0; i < Q; i++)	q[qry[i].second] = i;

	for(int k = 0, id = 0; k <= L; k++)	
	{
		while(k > qry[id].first && id < qry.size())	id++;
		K[k] = id;
	}

	for(int j = 1; j + L <= N; j++)
	{
		int k = 0;
		for(int i = 1; i <= L; i++) k += (a[i] != a[i + j]);

		ans[K[k]][1]++;
		ans[K[k]][1 + j]++;

//		printf("(1, %d) = %d\n", 1 + j, k);

		for(int i = 2; i + j + L - 1 <= N; i++)
		{
			k -= (a[i - 1] != a[i + j - 1]);
			k += (a[i + L - 1] != a[i + j + L - 1]);
			
//			printf("(%d, %d) = %d\n", i, i + j, k);

			ans[K[k]][i]++;
			ans[K[k]][i + j]++;
		}	
	}

	for(int i = 1; i < Q; i++)	
		for(int j = 1; j <= N; j++)
			ans[i][j] += ans[i - 1][j];

	for(int i = 0; i < Q; i++)
	{
		for(int j = 1; j + L - 1 <= N; j++)	printf("%d ", ans[q[i]][j]);
		printf("\n");
	}
}

Compilation message

lot.cpp: In function 'int main()':
lot.cpp:29:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(k > qry[id].first && id < qry.size()) id++;
                              ~~~^~~~~~~~~~~~
lot.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &L);
  ~~~~~^~~~~~~~~~~~~~~~~
lot.cpp:12:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= N; i++) scanf("%d", &a[i]);
                              ~~~~~^~~~~~~~~~~~~
lot.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &Q);
  ~~~~~^~~~~~~~~~
lot.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &k);
   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 21 ms 384 KB Output is correct
14 Correct 13 ms 640 KB Output is correct
15 Correct 12 ms 512 KB Output is correct
16 Correct 20 ms 640 KB Output is correct
17 Correct 18 ms 632 KB Output is correct
18 Correct 18 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 465 ms 508 KB Output is correct
2 Correct 480 ms 496 KB Output is correct
3 Correct 485 ms 504 KB Output is correct
4 Correct 468 ms 504 KB Output is correct
5 Correct 144 ms 632 KB Output is correct
6 Correct 425 ms 688 KB Output is correct
7 Correct 142 ms 512 KB Output is correct
8 Correct 248 ms 632 KB Output is correct
9 Correct 464 ms 632 KB Output is correct
10 Correct 466 ms 632 KB Output is correct
11 Correct 21 ms 384 KB Output is correct
12 Correct 251 ms 512 KB Output is correct
13 Correct 200 ms 512 KB Output is correct
14 Correct 192 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 465 ms 508 KB Output is correct
2 Correct 480 ms 496 KB Output is correct
3 Correct 485 ms 504 KB Output is correct
4 Correct 468 ms 504 KB Output is correct
5 Correct 144 ms 632 KB Output is correct
6 Correct 425 ms 688 KB Output is correct
7 Correct 142 ms 512 KB Output is correct
8 Correct 248 ms 632 KB Output is correct
9 Correct 464 ms 632 KB Output is correct
10 Correct 466 ms 632 KB Output is correct
11 Correct 21 ms 384 KB Output is correct
12 Correct 251 ms 512 KB Output is correct
13 Correct 200 ms 512 KB Output is correct
14 Correct 192 ms 512 KB Output is correct
15 Correct 450 ms 632 KB Output is correct
16 Correct 401 ms 632 KB Output is correct
17 Correct 484 ms 632 KB Output is correct
18 Correct 477 ms 632 KB Output is correct
19 Correct 476 ms 512 KB Output is correct
20 Correct 458 ms 632 KB Output is correct
21 Correct 477 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 21 ms 384 KB Output is correct
14 Correct 13 ms 640 KB Output is correct
15 Correct 12 ms 512 KB Output is correct
16 Correct 20 ms 640 KB Output is correct
17 Correct 18 ms 632 KB Output is correct
18 Correct 18 ms 632 KB Output is correct
19 Correct 465 ms 508 KB Output is correct
20 Correct 480 ms 496 KB Output is correct
21 Correct 485 ms 504 KB Output is correct
22 Correct 468 ms 504 KB Output is correct
23 Correct 144 ms 632 KB Output is correct
24 Correct 425 ms 688 KB Output is correct
25 Correct 142 ms 512 KB Output is correct
26 Correct 248 ms 632 KB Output is correct
27 Correct 464 ms 632 KB Output is correct
28 Correct 466 ms 632 KB Output is correct
29 Correct 21 ms 384 KB Output is correct
30 Correct 251 ms 512 KB Output is correct
31 Correct 200 ms 512 KB Output is correct
32 Correct 192 ms 512 KB Output is correct
33 Correct 450 ms 632 KB Output is correct
34 Correct 401 ms 632 KB Output is correct
35 Correct 484 ms 632 KB Output is correct
36 Correct 477 ms 632 KB Output is correct
37 Correct 476 ms 512 KB Output is correct
38 Correct 458 ms 632 KB Output is correct
39 Correct 477 ms 596 KB Output is correct
40 Correct 493 ms 1912 KB Output is correct
41 Correct 17 ms 1280 KB Output is correct
42 Correct 497 ms 2040 KB Output is correct
43 Correct 466 ms 1912 KB Output is correct
44 Correct 480 ms 1828 KB Output is correct
45 Correct 611 ms 8056 KB Output is correct
46 Correct 27 ms 4728 KB Output is correct
47 Correct 580 ms 8312 KB Output is correct
48 Correct 540 ms 6520 KB Output is correct
49 Correct 524 ms 7160 KB Output is correct